Operating System - HP-UX
1833159 Members
3247 Online
110051 Solutions
New Discussion

Re: socket receive program

 
alert0952
Occasional Contributor

socket recive program

 

I wrote a program but i always run 4 hours and keep loop

program is still alive but the program do nothing,

does any one know how to solve this problem

below is gdb information and source code

 

int
CHpuxSocket::readn(int fd, char *buf, unsigned int len)
{
//printf("INFO: HpuxSocket::readn\n");
int cnt;
int rc;
cnt = len;
int counter = 0;
try
{
while (cnt > 0)
{
rc = recv(fd,buf,cnt,0);
//printf("rc=%d\n",rc);
if (rc < 0)
{
if (counter >= 3)
{
return -1;
}
if (errno == EAGAIN)
{
counter++;
continue;
}
else
return -1;
}
if (rc == 0)
return len-cnt;
buf += rc;
cnt -= rc;
}
return len;
}
catch (...)
{
printf("ERROR: Exception happen\n");
return len;
}
}

 

 

 

Attaching to program: /usr/local/sbin/ISAgent/isAgent, process 1766

0x60000000c040b3f0:0 in _recv_sys+0x30 () from /usr/lib/hpux32/libc.so.1

(gdb) bt

#0  0x60000000c040b3f0:0 in _recv_sys+0x30 () from /usr/lib/hpux32/libc.so.1

#1  0x60000000c0420dc0:0 in recv+0x80 () from /usr/lib/hpux32/libc.so.1

warning:

ERROR: Use the "objectdir" command to specify the search path for objectfile CHpuxSocket.o.

If NOT specified will behave as a non -g compiled binary.

 

#2  0x431c190:0 in CHpuxSocket::readn(int,char*,unsigned int)+0xc0 ()

#3  0x431b1f0:0 in CHpuxSocket::GetSessionKey(char*,char*)+0x5b0 ()

warning:

ERROR: Use the "objectdir" command to specify the search path for objectfile irmassock.o.

If NOT specified will behave as a non -g compiled binary.

 

#4  0x40b4410:0 in irmassock::bAuthenticate()+0x70 ()

warning:

ERROR: Use the "objectdir" command to specify the search path for objectfile irmas.o.

If NOT specified will behave as a non -g compiled binary.

 

#5  0x40a92c0:0 in irmas::bConnectToServer(char*,int)+0x180 ()

#6  0x409e3a0:0 in irmas::bConnectToServer(int)+0x40 ()

#7  0x40a03c0:0 in irmas::Routine(int)+0x110 ()

warning:

ERROR: Use the "objectdir" command to specify the search path for objectfile irmas_main.o.

If NOT specified will behave as a non -g compiled binary.

 

#8  0x409afb0:0 in main+0xa90 ()

(gdb)

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: socket receive program

>try/catch

 

This is useless if you are just calling libc routines.  They don't throw C++ exceptions.

 

#1  0x60000000c0420dc0:0 in recv+0x80 /usr/lib/hpux32/libc.so.1

#2  0x431c190:0 in CHpuxSocket::readn(int,char*,unsigned int)+0xc0

 

The stacktrace just shows you waiting on a socket read.

 

(It also would help if you followed a consistent indentation policy.)

alert0952
Occasional Contributor

Re: socket receive program

Sorry I donot know how to solve this problem with

my problem is hang with recv() os library

 

(gdb) where
#0 0x60000000c037d010:0 in _recv_sys+0x30 () from /usr/lib/hpux32/libc.so.1
#1 0x60000000c03909b0:0 in recv+0x170 () from /usr/lib/hpux32/libc.so.1
#2 0x43154c0:0 in CHpuxSocket::readn () at hpux/CHpuxSocket.cpp:271
#3 0x43147b0:0 in CHpuxSocket::GetSessionKey () at hpux/CHpuxSocket.cpp:357
#4 0x40b1490:0 in irmassock::bAuthenticate () at irmassock.cpp:223
#5 0x40a6630:0 in irmas::bConnectToServer () at irmas.cpp:424
#6 0x409c730:0 in irmas::bConnectToServer () at irmas.cpp:402
#7 0x409e590:0 in irmas::Routine () at irmas.cpp:1209
#8 0x40994f0:0 in main () at irmas_main.cpp:344

 

below is my source code ,how to solve it

int
CHpuxSocket::readn(int fd, char *buf, unsigned int len)
{
//printf("INFO: HpuxSocket::readn\n");
int cnt;
int rc;
cnt = len;
int counter = 0;
try
{
while (cnt > 0)
{
rc = recv(fd,buf,cnt,0);
//printf("rc=%d\n",rc);
if (rc < 0)
{
if (counter >= 3)
{
return -1;
}
if (errno == EAGAIN)
{
counter++;
continue;
}
else
return -1;
}
if (rc == 0)
return len-cnt;
buf += rc;
cnt -= rc;
}
return len;
}
catch (...)
{
printf("ERROR: Exception happen\n");
return len;
}
}

 

 

 

Dennis Handly
Acclaimed Contributor

Re: socket receive program

>my problem is hang with recv(2)

 

This will hang unless you are in non-blocking mode.

(As I mentioned 9 months ago, remove the try/catch as useless on HP-UX.)