Unix Programming - accept problem

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2006 > accept problem





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author accept problem
Mex

2006-04-02, 7:41 pm

Hi,
I have some weird problem with the "accept" function in my C++ code.

Here the code:
if ((t=accept(descriptor,(struct sockaddr*)&client,&sz))<0){
perror("ServerTCPSocket::GetConnection()");
cout<<"errno:"<<errno<<endl;
cerr<<"accept returns "<<t<<endl;
return NULL;
}

The problems is that after a random period, the accept returns a
negative value even if no one has done a "connect", the negative value
returned is t = -512, perror says "Success" and errno=29.

Here the output that I got:

ServerTCPSocket::GetConnection(): Success
errno:29
accept returns -512

The questions are:
- why does "accept" fail without any "connect"?
- what is errno=29?
- is "-512" just a negative value or it has some meaning?

Thanks in advance,
Massimo

moi

2006-04-02, 7:41 pm

Mex wrote:
> Hi,
> I have some weird problem with the "accept" function in my C++ code.
>
> Here the code:
> if ((t=accept(descriptor,(struct sockaddr*)&client,&sz))<0){
> perror("ServerTCPSocket::GetConnection()");
> cout<<"errno:"<<errno<<endl;
> cerr<<"accept returns "<<t<<endl;
> return NULL;
> }


Try:
if ((t=accept(descriptor,(struct sockaddr*)&client,&sz)) == -1){}

Does it still print t= -512 ? Why ?

HTH,
AvK
mangesh sawant

2006-04-02, 7:41 pm

Stream sockets get destroyed automaticaly after some time they are
creaed . If u r using strem socket then u may have this problem .

Rainer Temme

2006-04-02, 7:41 pm

mangesh sawant wrote:
> Stream sockets get destroyed automaticaly after some time they are
> creaed . If u r using strem socket then u may have this problem .


nonsense!

Rainer
William Ahern

2006-04-02, 7:41 pm

On Wed, 22 Mar 2006 09:39:57 -0800, Mex wrote:

> Hi,
> I have some weird problem with the "accept" function in my C++ code.
>
> Here the code:
> if ((t=accept(descriptor,(struct sockaddr*)&client,&sz))<0){
> perror("ServerTCPSocket::GetConnection()");
> cout<<"errno:"<<errno<<endl;
> cerr<<"accept returns "<<t<<endl;
> return NULL;
> }
>
> The problems is that after a random period, the accept returns a
> negative value even if no one has done a "connect", the negative value
> returned is t = -512, perror says "Success" and errno=29.
>


errno is invalid after calling perror(). And you can't just switch them,
because outputting the value of errno can also change errno, so perror()
will print something irrelevant. Try

if (0 > (t = accept())) {
int sys_errno = errno;
perror("blah");
cout<<"errno:"<<sys_errno<<endl;
}

accept() returning -512 is very weird. What platform is this occurring on?


David Schwartz

2006-04-02, 7:41 pm


"Mex" <massimo.canonico@gmail.com> wrote in message
news:1143049197.250435.67130@z34g2000cwc.googlegroups.com...

> Here the code:
> if ((t=accept(descriptor,(struct sockaddr*)&client,&sz))<0){
> perror("ServerTCPSocket::GetConnection()");
> cout<<"errno:"<<errno<<endl;
> cerr<<"accept returns "<<t<<endl;
> return NULL;
> }


First, you don't tell us what type 't' is or what 'sz' is initialized
to. Your problems may be there.

Second, you output 'errno' after the call to 'perror'. Unfortunately,
'errno' is smart enough to somehow remember that you want the error that was
associated with the 'accept' call rather than any errors that may have
occured in the process of outputing the error message in 'perror'.

DS


Barry Margolin

2006-04-02, 7:41 pm

In article <dvslua$n69$1@nntp.webmaster.com>,
"David Schwartz" <davids@webmaster.com> wrote:

> "Mex" <massimo.canonico@gmail.com> wrote in message
> news:1143049197.250435.67130@z34g2000cwc.googlegroups.com...
>
>
> First, you don't tell us what type 't' is or what 'sz' is initialized
> to. Your problems may be there.
>
> Second, you output 'errno' after the call to 'perror'. Unfortunately,
> 'errno' is smart enough to somehow remember that you want the error that was


ITYM "not smart enough"

> associated with the 'accept' call rather than any errors that may have
> occured in the process of outputing the error message in 'perror'.
>
> DS


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
clayne

2006-04-02, 7:41 pm

mangesh sawant wrote:
> Stream sockets get destroyed automaticaly after some time they are
> creaed . If u r using strem socket then u may have this problem .


BS!

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com