Parial Write for sockets in LINUX -


we have server-client communication in our application. sockets used communication. using af_inet sockets sock_stream(tcp/ip). these sockets in non blocking mode (o_nonblock). application written in c++ on unix.

in our system server write socket , client read it. had written code handle partial writes. if partial happens, try 30 more times write entire data.

our server try write 2464 bytes socket. in cases not write entire data. server try writing 30 more times transfer entire data. of times entire data written within 30 tries. times after 30 reties sever wil not able write entire data. here throw eagain error. problem happens in client side when tries read partially written data.

consider server tried write 2464 bytes. after repeated 30 attempts write 1080 bytes. server raise eagain @ point. client try read 2464 bytes. read command return 2464 , hence read ok. data received corrupted 1 (partially written data only). client crashes.

can 1 please advise on following,

1) possible remove partially written data server itself. client not recieve corrupted incomplete data?. (we cannot use read() function server remove this. consider server written n messages socket. client in busy state , not able read them. server try write n+1 th message , partial write occured. if use read command server, entire n successfull messages alo removed. need remove partially witten (n+1 th) message only)

2) there way identify in client side had read partially written message?.

please note facing partial write issue in linux(redhat 5.4) only. system working fine in solaris (in solaris either eh entire data written or no data witll written in 30 tries of write).

thanks in advance.

there's terribly wrong in code.

  • you should call write many times necessary transfer data want, see no reason stop after 30 times

  • if you're using non-blocking sockets, should use select() (or poll(), or similar) notified when can write more data

  • there's wrong receiving end - if you've sent less 2464, shouldn't able read amount client socket. check value returned read() (i.e. number of bytes read)? again, on client side should use select() etc. , call read many times needed receive full message.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -