mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* problem with write() to a socket and EPIPE
@ 2001-06-18 14:36 oliver.kowalke
  2001-06-18 15:18 ` Richard B. Johnson
  0 siblings, 1 reply; 2+ messages in thread
From: oliver.kowalke @ 2001-06-18 14:36 UTC (permalink / raw)
  To: linux-kernel

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;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-06-18 15:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-18 14:36 problem with write() to a socket and EPIPE oliver.kowalke
2001-06-18 15:18 ` Richard B. Johnson

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®