c***@hotmail.com
2006-02-14 16:42:58 UTC
Hi,
The following function works 99.9% of the time, but every once in a
while, I get a valid socket connection but a failure on the write().
The errno=32 which I believe is a broken pipe. The code used to fail on
every interrupt (EINTR) signal, but from what I've read it seems this
can be expected and one should simply re-attempt the call to write() so
this code reflects that thinking. I've removed the read portion of the
function since it would just clutter things up for debugging purposes.
So what happens is every once in a while I get about 10 "write attempt"
messages followed by the "error on write" message with errno=32.
Any ideas?
Thanks,
Chris
int soapConnect ()
{
int sockfd;
int len, result;
struct sockaddr_in address;
struct hostent *hostinfo;
hostinfo = gethostbyname(ACC_IP);
if (!hostinfo) return(2);
sockfd = socket(AF_INET, SOCK_STREAM,0);
address.sin_family = AF_INET;
address.sin_port = (80);
address.sin_addr = *(struct in_addr *)*hostinfo -> h_addr_list;
len = sizeof(address);
if( (result = connect(sockfd, (struct sockaddr *)&address, len)) < 0 )
{
fprintf(stdout, "SOAP:\t:connect failed");
close(sockfd);
return(3);
}
do {
fprintf(stdout, "SOAP:\twrite attempt");
result = write(sockfd, &soapString, sizeof(soapString));
if( result < 1 && errno != EINTR ) {
fprintf(stdout,"SOAP:\terror on write() errno=%d",errno);
close(sockfd);
return(4);
}
if( errno == EINTR ) {
fprintf(stdout,"SOAP:\t:write interupted...tyring again");
continue;
}
fprintf(stdout, "SOAP:\twrite success");
break;
} while(1);
close(sockfd);
return(1);
}
The following function works 99.9% of the time, but every once in a
while, I get a valid socket connection but a failure on the write().
The errno=32 which I believe is a broken pipe. The code used to fail on
every interrupt (EINTR) signal, but from what I've read it seems this
can be expected and one should simply re-attempt the call to write() so
this code reflects that thinking. I've removed the read portion of the
function since it would just clutter things up for debugging purposes.
So what happens is every once in a while I get about 10 "write attempt"
messages followed by the "error on write" message with errno=32.
Any ideas?
Thanks,
Chris
int soapConnect ()
{
int sockfd;
int len, result;
struct sockaddr_in address;
struct hostent *hostinfo;
hostinfo = gethostbyname(ACC_IP);
if (!hostinfo) return(2);
sockfd = socket(AF_INET, SOCK_STREAM,0);
address.sin_family = AF_INET;
address.sin_port = (80);
address.sin_addr = *(struct in_addr *)*hostinfo -> h_addr_list;
len = sizeof(address);
if( (result = connect(sockfd, (struct sockaddr *)&address, len)) < 0 )
{
fprintf(stdout, "SOAP:\t:connect failed");
close(sockfd);
return(3);
}
do {
fprintf(stdout, "SOAP:\twrite attempt");
result = write(sockfd, &soapString, sizeof(soapString));
if( result < 1 && errno != EINTR ) {
fprintf(stdout,"SOAP:\terror on write() errno=%d",errno);
close(sockfd);
return(4);
}
if( errno == EINTR ) {
fprintf(stdout,"SOAP:\t:write interupted...tyring again");
continue;
}
fprintf(stdout, "SOAP:\twrite success");
break;
} while(1);
close(sockfd);
return(1);
}