select server send buf pointer mistake
wangdingqiao opened this issue · 1 comments
wangdingqiao commented
in function on_peer_ready_send from file : select-server.c
fd_status_t on_peer_ready_send(int sockfd) {
assert(sockfd < MAXFDs);
peer_state_t* peerstate = &global_state[sockfd];
if (peerstate->sendptr >= peerstate->sendbuf_end) {
// Nothing to send.
return fd_status_RW;
}
int sendlen = peerstate->sendbuf_end - peerstate->sendptr;
int nsent = send(sockfd, peerstate->sendbuf, sendlen, 0);
// ...
if (nsent < sendlen) {
peerstate->sendptr += nsent;
return fd_status_W;
} else {
// Everything was sent successfully; reset the send queue.
peerstate->sendptr = 0;
peerstate->sendbuf_end = 0;
// ...
}
}
I think this line:
int nsent = send(sockfd, peerstate->sendbuf, sendlen, 0);
shoule be:
int nsent = send(sockfd, peerstate->sendbuf+peerstate->sendptr, sendlen, 0);
eliben commented
Thank you! Fixed it in the code and will fix in the blog post too