c - IRC program not printing last message -
i had function receive info irc server in 512-byte chunks , print terminal window, went this:
int mainloop(redchan_t *redchan) { int socketdescriptor = redchan->socketdescriptor, i, bytesreceived; char workingbuffer[recvbuff] = {[0 ... recvbuff - 2] = '0', '\0'}; puts("recieving data..."); { if ((bytesreceived = recv( socketdescriptor, workingbuffer, recvbuff, 0)) == 0) exit(exit_failure); (i = 0; < bytesreceived; ++i) printf("%c", workingbuffer[i]); } while(1); homecoming 0; }
but wanted create more orthogonal took out phone call recv , set in own routine looks this:
int redchanrecv(redchan_t *redchan, int size, char *buffer) { int totalbytes = 0, bytesreceived; while (totalbytes < size) { if ((bytesreceived = recv( redchan->socketdescriptor, buffer + totalbytes, size - totalbytes, 0)) <= 0) cleanup_redchan(redchan, serverinfo); totalbytes += bytesreceived; } homecoming 0; }
i phone call redchanrecv() in each iteration of main loop , print buffer. when run it, prints out everything, except 1 line. lastly line never makes terminal (does create buffer?). sense i'm making rookie error hell if can see it. how can solve this?
stdout
line-buffered default in system, add together fflush(stdout)
phone call have lastly line printed.
c linux websocket irc berkeley-sockets
No comments:
Post a Comment