- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Problem about reading data on a TCP socket
Operating System - HP-UX
1748204
Members
4203
Online
108759
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2010 02:01 AM
тАО02-15-2010 02:01 AM
Problem about reading data on a TCP socket
I support an application compiled under HP10.20 and running on B2000 station under HP11.11, which is an HMI displaying data received from other equipments. This application is composed with several processes which one is dedicated to the communication between HMI processes and the application running under other equipments. The communication in this process is based on sockets and pipes : pipe with the HMI processes, socket UDP to manage the detection of clients, sockets TCP to receive and to send data from/to clients of other equipments when the connexion is established with them.
I think that the managment of the communications is classic :
- loop calling the select function to wait data from all the file descriptors of the sockets and pipes added through the FD_SET macro :
- check the return of the select function
- if the return of select function > 0, detection of the file descriptor concerned through the FD_ISSET macro
- call recv function on the file descriptor concerned
Code extract :
sel=0;
selT.tv_sec=5;
selT.tv_usec=0;
while (sel == 0)
{
sel = select(NbFd, &fdr, &fdw, &fde, &selT);
}
...
if (sel>0)
{
...
if (FD_ISSET(sock, &fdr)
ret = recv(sock, ...
Problem is that sometimes, when there is much traffic, the return of the select function (sel) is >0, the file descriptor detected is a TCP socket, but the recv function on this TCP socket returns 0 (ret). Our application treats that as a disconnexion !
How may you explain that the select function detects data on a socket (return>0) and that the recv function on this socket is unable to read the data (return=0)?
I think that the managment of the communications is classic :
- loop calling the select function to wait data from all the file descriptors of the sockets and pipes added through the FD_SET macro :
- check the return of the select function
- if the return of select function > 0, detection of the file descriptor concerned through the FD_ISSET macro
- call recv function on the file descriptor concerned
Code extract :
sel=0;
selT.tv_sec=5;
selT.tv_usec=0;
while (sel == 0)
{
sel = select(NbFd, &fdr, &fdw, &fde, &selT);
}
...
if (sel>0)
{
...
if (FD_ISSET(sock, &fdr)
ret = recv(sock, ...
Problem is that sometimes, when there is much traffic, the return of the select function (sel) is >0, the file descriptor detected is a TCP socket, but the recv function on this TCP socket returns 0 (ret). Our application treats that as a disconnexion !
How may you explain that the select function detects data on a socket (return>0) and that the recv function on this socket is unable to read the data (return=0)?
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-15-2010 03:31 AM
тАО02-15-2010 03:31 AM
Re: Problem about reading data on a TCP socket
From "man 2 recv":
--------
+ If 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), recv() returns 0.
--------
So treating it as a disconnection *is* exactly the right thing to do.
select() indicates the socket has received something... and the result of 0 from recv() indicates that the "something" was an end-of-stream indication.
MK
--------
+ If 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), recv() returns 0.
--------
So treating it as a disconnection *is* exactly the right thing to do.
select() indicates the socket has received something... and the result of 0 from recv() indicates that the "something" was an end-of-stream indication.
MK
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2010 02:53 AM
тАО02-18-2010 02:53 AM
Re: Problem about reading data on a TCP socket
OK thanks, but for the moment, nothing could explain why the equipment connected at the other side of the socket would close the socket ...
Is it the unique possible cause of the described effects, in a context of important traffic ?
Is it the unique possible cause of the described effects, in a context of important traffic ?
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP