26
* None of this code is thread safe, if you want to use it in a multi-threaded
27
* context, please protect it with a mutex.
29
* First, create a writer with sp_writer_create()
30
* And selectes() on the socket from sp_get_fd()
31
* If the socket is closed or there are errors from any function, the app
32
* should call sp_close() and assume the writer is dead
33
* The server calls sp_writer_accept_client() when there is something to read
35
* It then needs to select() on the socket from sp_writer_get_client_fd()
36
* If it gets an error on that socket, it call sp_writer_close_client().
37
* If there is something to read, it calls sp_writer_recv().
39
* The writer allocates buffers with sp_writer_alloc_block(),
40
* writes something in the buffer (retrieved with sp_writer_block_get_buf(),
41
* then calls sp_writer_send_buf() to send the buffer or a subsection to
42
* the other side. When it is done with the block, it calls
43
* sp_writer_free_block().
44
* If alloc fails, then the server must wait for events from the clients before
48
* The clients connect with sp_client_open()
49
* And select() on the fd from sp_get_fd() until there is something to read.
50
* Then they must read using sp_client_recv() which will return > 0 if there
51
* is a valid buffer (which is read only). It will return 0 if it is an internal
52
* message and <0 if there was an error. If there was an error, one must close
53
* it with sp_close(). If was valid buffer was received, the client must release
54
* it with sp_client_recv_finish() when it is done reading from it.
26
* None of this code is thread safe, if you want to use it in a
27
* multi-threaded context, please protect it with a mutex.
29
* First, create a writer with sp_writer_create(), then select() on
30
* the socket returned by sp_get_fd(). If the socket is closed or any
31
* function returns an error, the app should call sp_close() and
32
* assume the other side is dead. The writer calls
33
* sp_writer_accept_client() when there is something to read from the
34
* main server fd. This returns a new ShmClient (representing a client
35
* connection), the writer needs to do a select() on the socket
36
* returned by sp_writer_get_client_fd(). If it gets an error on that
37
* socket, it calls sp_writer_close_client(). If there is something to
38
* read, it calls sp_writer_recv().
40
* The writer allocates a block containing a free buffer with
41
* sp_writer_alloc_block(), then writes something in the buffer
42
* (retrieved with sp_writer_block_get_buf(), then calls
43
* sp_writer_send_buf() to send the buffer or a subsection to the
44
* other side. When it is done with the block, it calls
45
* sp_writer_free_block(). If alloc fails, then the server must wait
46
* for events on the client fd (the ones where sp_writer_recv() is
47
* called), and then try to re-alloc.
49
* The reader (client) connect to the writer with sp_client_open() And
50
* select()s on the fd from sp_get_fd() until there is something to
51
* read. Then they must read using sp_client_recv() which will return
52
* the size of the buffer (positive) if there is a valid buffer (which
53
* is read only). It will return 0 if it is an internal message and a
54
* negative number if there was an error. If there was an error, the
55
* application must close the pipe with sp_close() and assume that all
56
* buffers are no longer valid. If was valid buffer was received, the
57
* client must release it with sp_client_recv_finish() when it is done