Skip to content

Instantly share code, notes, and snippets.

@RunsFor
Created April 9, 2019 10:03
Show Gist options
  • Save RunsFor/cd28605c8c85cdaaa2300a14f2a7055f to your computer and use it in GitHub Desktop.
Save RunsFor/cd28605c8c85cdaaa2300a14f2a7055f to your computer and use it in GitHub Desktop.
This gist shows inconsistent behaviour of tarantool's socket:receive function which internally uses different buffers for different types of calls
Tarantool 2.1.1-434-g881c7b59b
type 'help' for interactive help
tarantool> socket = require('socket')
---
...
tarantool> fiber = require'fiber'
---
...
tarantool> chan = fiber.channel()
---
...
tarantool> fn = function(s) counter = 0; while true do s:write((tostring(counter)):rep(chan:get())); counter = counter + 1 end end
---
...
tarantool> socket.tcp_server('0.0.0.0', 8888, fn)
started
---
- fd: 6
name:
host: 0.0.0.0
family: AF_INET
type: SOCK_STREAM
protocol: tcp
port: 8888
- host: 0.0.0.0
family: AF_INET
type: SOCK_STREAM
protocol: tcp
port: 8888
...
tarantool> s = socket.connect('localhost', 8888)
---
...
tarantool> chan:put(5)
---
- true
...
tarantool> chan:put(5)
---
- true
...
tarantool> s:receive(5)
---
- '00000'
...
tarantool> chan:put(5)
---
- true
...
tarantool> s:settimeout(1)
---
- 1
...
tarantool> s:receive('*a')
---
- '22222'
...
tarantool> s:receive(5)
---
- '11111'
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment