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 .

Come unire piu' file pdf usando MAC OS

To join two or more pdf files together using Preview (the standard pdf viewer in OS X) simply open a pdf in preview, open the thumbnail view (Shift-⌘-D), and then drag a second pdf file ON TOP OF an existing page thumbnail. The two documents will merge into one. Then save the new combined file. Read on for step-by-step instructions. Combining pdf documents in OSX is easy. Leopard and Snow Leopard have the ability to move pdf pages around and even merge two pdf documents together. It’s built right in to OS X – you don’t need a third party program to do it! SUMMARY: To merge the two PDF files you need to drag the new pdf ON TOP OF an existing thumbnail. If you drag it into the sidebar but not on top of an existing page the new file will be added as an external link – not merged into the original pdf document. See these two pictures below to visualise the difference. Questo articolo e' stato copiato dal sito: http://macintoshhowto.com/leopard/how-to-merge-pdf-files-with-preview-in...