From: oliver.kowalke@t-online.de
To: linux-kernel@vger.kernel.org
Subject: problem with write() to a socket and EPIPE
Date: Mon, 18 Jun 2001 16:36:23 +0200 (MEST) [thread overview]
Message-ID: <992874658.3b2e10a2ef441@webmail.t-online.de> (raw)
Hello,
I've the following problem.
If the peer has closed its socket connection the second write to this
socket should return -1 and errno should be set to EPIPE (if SIGPIPE is
set
to be ignored). This never happens with my code. Why?
OS: Linux (Debian 2.2r3)
kernel: 2.4.4
compiler: gcc-2.95.2
c-lib: libc-2.1.3
with best regards,
Oliver
(writen() is a member function of my socket C++-class)
ssize_t
sock::writen( const void * vptr, size_t n)
{
size_t nleft;
ssize_t nwritten;
const char *ptr;
ptr = static_cast< char * >( vptr);
nleft = n;
struct sigaction new_sa;
struct sigaction old_sa;
new_sa.sa_handler = SIG_IGN;
::sigemptyset( & new_sa.sa_mask);
new_sa.sa_flags = 0;
::sigaction( SIGPIPE, & new_sa, & old_sa);
while ( nleft > 0)
{
if ( ( nwritten = ::write( m_handle, ptr, nleft) ) <=
0)
{
if ( errno == EINTR)
nwritten = 0; /* and call
write() again */
else if ( errno == EPIPE)
return EOF; /* write to
socket with no readers */
else
throw net_io_ex( ::strerror( errno),
"writen()", __FILE__); /* error */
}
nleft -= nwritten;
ptr += nwritten;
}
/* set to its previous action */
::sigaction( SIGPIPE, & old_sa, 0);
return n;
}
next reply other threads:[~2001-06-18 14:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-18 14:36 oliver.kowalke [this message]
2001-06-18 15:18 ` Richard B. Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=992874658.3b2e10a2ef441@webmail.t-online.de \
--to=oliver.kowalke@t-online.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®