 |
|
 |
|
08-28-05 10:50 PM
Hello,
can anybody tell me why in this source connect say that a connect is
possible while it is sure not!
I've done a calculation error with the port and I've spend hours to find
out why I got a SIGPIPE signal in my program.
It's the same if the socket is blocking or non-blocking.
greetings,
daniel
int c_rv = connect(pCli->sockPort, (struct
sockaddr*)&pCli->sockaddr_in_port, sizeof(struct sockaddr_in));
if( c_rv<0 ) {
int n;
struct timeval tv={3,0};
fd_set fd;
FD_ZERO(&fd);
FD_SET(pCli->sockPort, &fd);
n=select(pCli->sockPort+1, 0,&fd,0, &tv);
if( n!=1 ) {
TRACE(" - CONNECT TIMEOUT\n");
close(pCli->sockPort);
goto end;
}
TRACE(" - port connected\n");
rv = 1;
}
else if( c_rv == 0 ) {
rv = 1;
TRACE(" - port connected\n");
}
else {
TRACE("connect port FAIL, err %s\n", strerror(errno));
}
end:
return rv;
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
08-29-05 01:48 AM
In article <43122958$0$27164$91cee783@newsreader01.highway.telekom.at>,
"Daniel W." <daw...@aon.at> wrote:
> Hello,
>
> can anybody tell me why in this source connect say that a connect is
> possible while it is sure not!
>
> I've done a calculation error with the port and I've spend hours to find
> out why I got a SIGPIPE signal in my program.
Maybe there's another server listening on the mistaken port you're
connecting to.
>
> It's the same if the socket is blocking or non-blocking.
>
> greetings,
> daniel
>
>
> int c_rv = connect(pCli->sockPort, (struct
> sockaddr*)&pCli->sockaddr_in_port, sizeof(struct sockaddr_in));
> if( c_rv<0 ) {
> int n;
> struct timeval tv={3,0};
> fd_set fd;
> FD_ZERO(&fd);
> FD_SET(pCli->sockPort, &fd);
> n=select(pCli->sockPort+1, 0,&fd,0, &tv);
> if( n!=1 ) {
> TRACE(" - CONNECT TIMEOUT\n");
> close(pCli->sockPort);
> goto end;
> }
> TRACE(" - port connected\n");
> rv = 1;
> }
> else if( c_rv == 0 ) {
> rv = 1;
> TRACE(" - port connected\n");
> }
> else {
> TRACE("connect port FAIL, err %s\n", strerror(errno));
> }
>
> end:
> return rv;
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
08-29-05 07:52 AM
Daniel W. wrote:
> Hello,
>
> can anybody tell me why in this source connect say that a connect is
> possible while it is sure not!
>
> I've done a calculation error with the port and I've spend hours to find
> out why I got a SIGPIPE signal in my program.
>
> It's the same if the socket is blocking or non-blocking.
>
> greetings,
> daniel
>
>
> int c_rv = connect(pCli->sockPort, (struct
> sockaddr*)&pCli->sockaddr_in_port, sizeof(struct sockaddr_in));
> if( c_rv<0 ) {
> int n;
> struct timeval tv={3,0};
> fd_set fd;
> FD_ZERO(&fd);
> FD_SET(pCli->sockPort, &fd);
> n=select(pCli->sockPort+1, 0,&fd,0, &tv);
> if( n!=1 ) {
> TRACE(" - CONNECT TIMEOUT\n");
> close(pCli->sockPort);
> goto end;
> }
Don't assume it is a timeout just because n != 1.
Check for errors, as always.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
08-29-05 07:52 AM
Nils O. Selåsdal wrote:
> Daniel W. wrote:
>
>
> Don't assume it is a timeout just because n != 1.
> Check for errors, as always.
Oh, it would help quite a bit if you pinpoint where your code received
the SIGPIPE, use a debugger.
(Mind you , it is pretty useless to try to help by this
little snippet, your datatypes and initialization part is missing.
)
[ Post a follow-up to this message ]
|
|
|
 |
|
|
08-29-05 12:50 PM
On Mon, 29 Aug 2005 09:08:16 +0200,
Nils O. Selåsdal <NOS@Utel.no> wrote:
> Don't assume it is a timeout just because n != 1.
> Check for errors, as always.
Also, don't assume that when connect returns an error that connect is
in progress.
Villy
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
08-29-05 12:50 PM
Daniel W. wrote:
> Hello,
>
> can anybody tell me why in this source connect say that a connect is
> possible while it is sure not!
It does not say so. You don't check errors correctly. A socket is
marked as ready for read/write if it has an outstanding error.
> I've done a calculation error with the port and I've spend hours to find
> out why I got a SIGPIPE signal in my program.
This is because select() tells you that the socket is ready for write
not because it has connected, rather because it has an outstanding
error.
> int c_rv = connect(pCli->sockPort, (struct
> sockaddr*)&pCli->sockaddr_in_port, sizeof(struct sockaddr_in));
> if( c_rv<0 ) {
Replace the check with if( c_rv<0 && EINPROGRESS == errno )
> int n;
> struct timeval tv={3,0};
> fd_set fd;
> FD_ZERO(&fd);
> FD_SET(pCli->sockPort, &fd);
> n=select(pCli->sockPort+1, 0,&fd,0, &tv);
> if( n!=1 ) {
> TRACE(" - CONNECT TIMEOUT\n");
> close(pCli->sockPort);
> goto end;
> }
You need a check here:
int err;
socklen_t err_len = sizeof err;
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &err_len)
|| err_len != sizeof err
|| err
)
// handle connect error
> TRACE(" - port connected\n");
> rv = 1;
> }
> else if( c_rv == 0 ) {
> rv = 1;
> TRACE(" - port connected\n");
> }
> else {
> TRACE("connect port FAIL, err %s\n", strerror(errno));
> }
>
> end:
> return rv;
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
08-29-05 11:00 PM
Daniel W. wrote:
> I've done a calculation error with the port and I've spend hours to find
> out why I got a SIGPIPE signal in my program.
Because you write to an invalid socket and have not blocked SIGPIPE signal.
signal(SIGPIPE, SIG_IGN) will help you not to get SIGPIPE, but -1 as return
value and errno with error code. Others commented on you connection code.
--
Anton Petrusevich
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 06:11 AM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|