土曜日, 11月 25, 2006

SIGPIPE

TCPのsocket書き込み時等に,既に相手側が閉じていたら,SIGPIPEが投げられる.
SIGPIPEが飛んでくるとアプリケーションが終了してしまうので,SIGPIPEを捕捉しなければいけないっぽい.
writeやsendtoに失敗した場合,errnoにはEPIPEがセットされる.
WRITE(2)                    BSD System Calls Manual                   WRITE(2)

NAME
write, writev, pwrite - write output

...

ERRORS
Write(), writev(), and pwrite() will fail and the file pointer will
remain unchanged if:
[EPIPE] An attempt is made to write to a pipe that is not open
for reading by any process.

[EPIPE] An attempt is made to write to a socket of type
SOCK_STREAM that is not connected to a peer socket.

0 件のコメント: