Operating System - Linux
1753809 Members
8727 Online
108805 Solutions
New Discussion юеВ

Re: recv error: Function is not available 0 251

 
moorthyp
Occasional Advisor

recv error: Function is not available 0 251

Hello all,

I have a query

i have written one small program .it will send and recv data continously.
My problem is:-
1.if i run this same program in linux .its working fine but if i run in HP-UX11iv1(PARISC) machine .i am getting following error

"recv error: Function is not available 0 251"

can u tell me .is it server regarding issue ?
how to fix this one?

Thanks in advance

Regards,
Moorthy

4 REPLIES 4
Sandman!
Honored Contributor

Re: recv error: Function is not available 0 251

Make sure you are compiling with the proper include files and libraries. Could you post the program here (if it isn't big) as that might help in troubleshooting it.
moorthyp
Occasional Advisor

Re: recv error: Function is not available 0 251

this is my code
can u tell me is there any mistake

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
fd_set rd_set;
fd_set wr_set;
fd_set er_set;
int maxFds = 16;

using namespace std;

#define PKT_LEN 1124
#define PORT_NUM 1707

int main ()
{
int nSocket, sockFd;
unsigned char *pktBuf = new unsigned char[PKT_LEN];
struct sockaddr_in serv, cli;
struct sockaddr fromAddr;
int fromLen = sizeof (fromAddr);
int clilen = sizeof (cli);

int bytesReceived;
int pktsRecvd = 1;
int pktsSent = 1;
int selRet;
// struct protoent *ptent;
//
// ptent = getprotobyname ("TCP");
// printf ("TCP PROTOCOL No. %d - %s\n", ptent->p_proto, ptent->p_name);
if ( (nSocket = socket(AF_INET, SOCK_STREAM, 6)) < 0) {
perror ("socket error");
return -1;
}
cout << "Socket# " << nSocket << endl;

memset(&serv, 0, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = htonl(INADDR_ANY);
serv.sin_port = htons(PORT_NUM);

if (bind(nSocket, (struct sockaddr *)&serv, sizeof(serv)) < 0) {
perror ("bind error");
return -1;
}

if (listen(nSocket, SOMAXCONN) < 0) {
perror ("listen error");
return -1;
}
//clilen = sizeof(cli);
if ((sockFd = accept(nSocket, (struct sockaddr *)&cli,(socklen_t *)&clilen )) < 0) {
perror ("accept error");
return -1;
}

FD_ZERO (&rd_set);
FD_ZERO (&wr_set);
FD_ZERO (&er_set);

FD_SET (sockFd, &rd_set);
// FD_SET (sockFd, &wr_set);
// FD_SET (sockFd, &er_set);

while (1)
{

// if ((bytesReceived = recvfrom (sockFd, pktBuf, 1024,
// 0, &fromAddr, &fromLen)) <= 0)
if ((selRet = select (maxFds, &rd_set, &wr_set, &er_set, NULL)) < 0)
{
perror ("select error");
return -1;
}
cout << "Select returned - " << selRet << endl;

cout << "Checking if Error is set...";
if (FD_ISSET (sockFd, &er_set))
{
perror ("socket error");
return -1;
}
cout << " No error\n";

cout << "Checking if Read is set...";
if (FD_ISSET (sockFd, &rd_set))
{
cout << " Reading\n";
if ((bytesReceived = recv (sockFd, pktBuf, PKT_LEN, 0)) <= 0)
{
perror ("recv error");
cout << bytesReceived << " " << errno << endl;
return -1;
}
cout << bytesReceived << " Bytes reveived\n";
cout << "recvd pkt no. - " << pktsRecvd++ << endl;
FD_CLR (sockFd, &rd_set);
FD_SET (sockFd, &wr_set);
}

cout << "Checking if Write is set...";
if (FD_ISSET (sockFd, &wr_set))
{
fromLen = sizeof (fromAddr);
cout << " Writing\n";
if (send (sockFd, (const void *)pktBuf, bytesReceived, 0) != bytesReceived)
{
perror ("send error");
return -1;
}
cout << "sent pkt no. - " << pktsSent++ << endl;
FD_CLR (sockFd, &wr_set);
FD_SET (sockFd, &rd_set);
}
}
}
Dennis Handly
Acclaimed Contributor

Re: recv error: Function is not available 0 251

if ((bytesReceived = recv (sockFd, pktBuf, PKT_LEN, 0)) <= 0) {
perror ("recv error");
cout << bytesReceived << " " << errno << endl;

Your error checking on this code is bad. If recv returns 0, you must not call perror nor print errno.

recv(2) says it returns 0 for:
The socket is blocking and the transport connection to the
remote node failed, or the remote side of a connection-based
socket has performed an orderly shutdown and there is no
more data to read (the socket has reached the end of its
data stream). Sockets with the O_NDELAY flag set may also
return 0 at any time when there is no data available.
moorthyp
Occasional Advisor

Re: recv error: Function is not available 0 251

thank u sir.
i will check it and come back to u


Regards
moorthy.p