Passa ai contenuti principali

C++ chiusura improvvisa connessione TCP

Puo' capitare che bruscamente, dopo che la connessione sia stata stabilita, uno dei due peer vada giu'. In questo caso, l'altro peer non si comporta correttamente. Di default, la receive ritorna 0 come numero di bytes ricevuti, per cui il peer non si accorge che l'altro peer non e' attivo, mentre la send ritorna -1, setta la variabile errno al valore EPIPE e lancia il segnale SIGPIPE, che normalmente fa uscire il processo.

Per evitare che il processo termini in seguito al segnale SIGPIPE si puo' settare l'opzione MSG_NOSIGNAL nella send in modo che il segnale SIGPIPE venga ingnorato.

In particolare:


iNumBytes = send(iSocket, _vMessage, _iMessageSize, MSG_NOSIGNAL);
if(iNumBytes == -1)
{
if(errno == EPIPE)
{
// gestisco l'errore
return 0;
}
}


Nel caso della receive, invece posso semplicemente gestire il caso in cui il numero di bytes ritornati e' 0.

Post popolari in questo blog

Excel 2007: Histograms with different textures

Select the series in the histogram Open Visual Basic terminal by typing ALT + F11 Open the Visual Basic editor by typing CTRL + G In the Immediate Window, type the following and press enter: selection.fill.patterned (4) I would like to thank Diego M. Oppenheimer who wrote this wonderful guide .

How to embed fonts into a pdf file

IEEE requires that your PDF files embed all fonts. Earlier, I told you how to get pdflatex LaTeX to embed all its fonts, but what if you are including figures that have hanging fonts and you are getting desperate? Luke Fletcher gives us the solution. 1. convert to ps: pdftops ICRA05.pdf 2. convert back to pdf using prepress settings: ps2pdf14 -dPDFSETTINGS=/prepress ICRA05.ps 3. check new ICRA05.pdf for horrendous formatting errors due to double conversion. source from http://www.daniel-lemire.com/blog/archives/2006/08/18/embedding-fonts-for-ieee/