[prev in list] [next in list] [prev in thread] [next in thread]
List: hpux-cxx-dev
Subject: CXX-DEV: RE: aCC query:Problem using SO_RCVTIMEO in setsockopt
From: "Sridhar Gudipati" <sridhargudipati () xius ! org>
Date: 2004-10-27 15:47:24
Message-ID: 01c101c4bc3a$943cbcb0$5896a8c0 () xius ! ltd
[Download RAW message or body]
Please find my select() function call here.
recvStr[NUM_BYTES-1]= 0;
struct timeval to;
fd_set rread;
int socketopen=1;
int sr,rval;
struct timeval before, after, lapsed;
struct timezone tzone;
gettimeofday(&before,&tzone); // Get timeofday before Select
while(1)
{
do
{
FD_ZERO(&rread); // clear the fd_set
FD_SET(i_Socket,&rread);
memset((char *)&to,0,sizeof(to));// clear the timeval struct
to.tv_sec = 0;
to.tv_usec = 100000; // 0.1 seconds timeout for select
sr=select(i_Socket+1, &rread, (fd_set *)0, (fd_set *)0, &to);
if (sr<0) //no data.
{
continue;
}
if (sr==0) // just finished reading data.
{
gettimeofday(&after,&tzone);
if (before.tv_usec > after.tv_usec)
{
after.tv_usec += 1000000;
after.tv_sec--;
}
lapsed.tv_usec = after.tv_usec - before.tv_usec;
lapsed.tv_sec = after.tv_sec - before.tv_sec;
if(lapsed.tv_sec > 5)
{
close(i_Socket);
return false;
}
break;
}
if (sr>0) // receive the data from socket.
{
gettimeofday(&before,&tzone);
if (FD_ISSET(i_Socket,&rread))
{
if ((rval=recv(i_Socket,recvStr,NUM_BYTES-1,0)) <= 0)
{
if (-1==rval)
{
close(i_Socket);
return false;
}
if (0==rval)
{
close(i_Socket);
return false;
}
socketopen=0;
}
else
{
recvStr[rval]=0;
str.append(recvStr);
}
}
}
}while(socketopen);
........
........
-----Original Message-----
From: owner-cxx-dev@cxx.cup.hp.com
[mailto:owner-cxx-dev@cxx.cup.hp.com]On Behalf Of Maucci, Cyrille
Sent: Wednesday, October 27, 2004 8:55 PM
To: Sridhar Gudipati; Streiber, Mario; cxx-dev@cxx.cup.hp.com
Subject: CXX-DEV: RE: CXX-DEV: RE : CXX-DEV: aCC query:Problem using
SO_RCVTIMEO in setsockopt
man 2 select
If the timeout argument is a null pointer, select() blocks until an
event
causes one of the masks to be returned with a valid (non-zero) value.
If the time limit expires before any event occurs that would cause one
of the masks to be set to a non-zero value, select() completes
successfully and returns 0.
Can you copy/paste your select call?
++Cyrille
-----Original Message-----
From: Sridhar Gudipati [mailto:sridhargudipati@xius.org]
Sent: mercredi 27 octobre 2004 17:12
To: Maucci, Cyrille; Streiber, Mario; cxx-dev@cxx.cup.hp.com
Subject: RE: CXX-DEV: RE : CXX-DEV: aCC query:Problem using SO_RCVTIMEO in
setsockopt
My select() is not returning as soon as something arrives. That's the
problem.
If i pump something,it is returning only if it timeouts.
-----Original Message-----
From: owner-cxx-dev@cxx.cup.hp.com
[mailto:owner-cxx-dev@cxx.cup.hp.com]On Behalf Of Maucci, Cyrille
Sent: Wednesday, October 27, 2004 7:58 PM
To: Sridhar Gudipati; Streiber, Mario; cxx-dev@cxx.cup.hp.com
Subject: CXX-DEV: RE : CXX-DEV: aCC query:Problem using SO_RCVTIMEO in
setsockopt
Hi
in your case, don't call select thousands of time with 0.1 sec timeout.
call it once with a 5 minutes timeout.
select() will return as soon as something arrives on your fd.
++Cyrille
________________________________
De: owner-cxx-dev@cxx.cup.hp.com de la part de Sridhar Gudipati
Date: mer. 27/10/2004 16:15
@: Streiber, Mario; cxx-dev@cxx.cup.hp.com Objet : RE: CXX-DEV: aCC
query:Problem using SO_RCVTIMEO in setsockopt
Dear Mario,
We are trying implement recv timeout like this. We don't know when we get
the
request. So select timeouts for every 0.1 second.
If select() is idle for 5 mins, then we close the socket. Polling every 0.1
seconds by 100 threads is taking CPU.
Best Regards,
Sridhar
(on behalf of Hari)
recvStr[NUM_BYTES-1]= 0;
struct timeval to;
fd_set rread;
int socketopen=1;
int sr,rval;
struct timeval before, after, lapsed;
struct timezone tzone;
gettimeofday(&before,&tzone); // Get timeofday before Select
while(1)
{
do
{
FD_ZERO(&rread); // clear the fd_set
FD_SET(i_Socket,&rread);
memset((char *)&to,0,sizeof(to));// clear the timeval struct
to.tv_sec = 0;
to.tv_usec = 100000; // 0.1 seconds timeout for select
sr=select(i_Socket+1, &rread, (fd_set *)0, (fd_set *)0, &to);
if (sr<0) //no data.
{
continue;
}
if (sr==0) // just finished reading data.
{
gettimeofday(&after,&tzone);
if (before.tv_usec > after.tv_usec)
{
after.tv_usec += 1000000;
after.tv_sec--;
}
lapsed.tv_usec = after.tv_usec - before.tv_usec;
lapsed.tv_sec = after.tv_sec - before.tv_sec;
if(lapsed.tv_sec > 5)
{
close(i_Socket);
return false;
}
break;
}
if (sr>0) // receive the data from socket.
{
gettimeofday(&before,&tzone);
if (FD_ISSET(i_Socket,&rread))
{
if ((rval=recv(i_Socket,recvStr,NUM_BYTES-1,0)) <= 0)
{
if (-1==rval)
{
close(i_Socket);
return false;
}
if (0==rval)
{
close(i_Socket);
return false;
}
socketopen=0;
}
else
{
recvStr[rval]=0;
str.append(recvStr);
}
}
}
}while(socketopen);
-----Original Message-----
From: owner-cxx-dev@cxx.cup.hp.com
[mailto:owner-cxx-dev@cxx.cup.hp.com]On Behalf Of Streiber, Mario
Sent: Wednesday, October 27, 2004 7:07 PM
To: cxx-dev@cxx.cup.hp.com
Subject: RE: CXX-DEV: aCC query:Problem using SO_RCVTIMEO in setsockopt
> We tried using select() but it is expensive in the sense, taking lot
> of CPU. Is there any option like SO_REVTIMEO for recv timeout ??
I don't know of a timeout option for recv. But that doesn't mean there is
none.
How can select() take a lot of CPU? select() blocks until one of the fd's
passed to it is ready for reading, writing or has an error condition. Or
until
the specified time is up. I have never seen a case where select causes CPU
load.
Mario
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE cxx-dev
_________________________________________________________________
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic