c - using splice with socket may cause starvation -


i'm writing tcp proxy, using edge-triggered epoll monitor fd, splice transmit data. here problem: how know socket receive buffer empty?

for example, if call read(2) asking read amount of data , read(2) returns lower number of bytes, can sure of having exhausted read i/o space file descriptor.

but found splice(sock, 0, pfd[1], 0, 65536, splice_f_nonblock) < 65536 may lead starvation.

o_nonblock enabled, n > pipe_buf if pipe full, write(2) fails, errno set eagain. otherwise, 1 n bytes may written (i.e., "partial write" may occur; caller should check return value write(2) see how many bytes written), , these bytes may interleaved writes other processes.

so should repeat calling splice till eagain? how can know whether socket receive buffer empty or pipe buffer full?

maybe can use getsockopt syscall so_error, , known socket eagain, , use epoll watch read/write event of socket.

i have problem when adding reverse http proxy web server, deem should work, though i'm not sure if best solution.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -