Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Getting the status of a socket through code

Reply
Thread Tools

Getting the status of a socket through code

 
 
oshaer
Guest
Posts: n/a
 
      12-11-2011
Hi Everybody


I need to write a code that forcibly closes connections that are in
CLOSE_WAIT status. It should run at a father process and constantly
check the forked child processes(servers). I need this code to work on
Unix/Linux, thus usage of WINAPI is not possible.

My question is:

1) Should I use netstat through code and parse the result to learn
which socket is in a CLOSE_WAIT situation?

2) Is there any C++ code that enables me to easily get socket status,
given the file descriptor number?

3) If you have any other ideas/recommendations please share.

Thanks a lot.
Ofira.


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-11-2011
On 12/11/2011 9:41 AM, oshaer wrote:
> I need to write a code that forcibly closes connections that are in
> CLOSE_WAIT status. It should run at a father process and constantly
> check the forked child processes(servers). I need this code to work on
> Unix/Linux, thus usage of WINAPI is not possible.
>
> My question is:
>
> 1) Should I use netstat through code and parse the result to learn
> which socket is in a CLOSE_WAIT situation?
>
> 2) Is there any C++ code that enables me to easily get socket status,
> given the file descriptor number?
>
> 3) If you have any other ideas/recommendations please share.


Sockets are platform-specific. Please consider asking in the newsgroup
dedicated to your OS/platform.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Tobias Müller
Guest
Posts: n/a
 
      12-11-2011
Leigh Johnston <(E-Mail Removed)> wrote:
> On 11/12/2011 14:41, oshaer wrote:
>> Hi Everybody
>>
>>
>> I need to write a code that forcibly closes connections that are in
>> CLOSE_WAIT status. It should run at a father process and constantly
>> check the forked child processes(servers). I need this code to work on
>> Unix/Linux, thus usage of WINAPI is not possible.
>>
>> My question is:
>>
>> 1) Should I use netstat through code and parse the result to learn
>> which socket is in a CLOSE_WAIT situation?
>>
>> 2) Is there any C++ code that enables me to easily get socket status,
>> given the file descriptor number?
>>
>> 3) If you have any other ideas/recommendations please share.

>
> Off-topic.
>
> HTH.
>
> /Leigh


Not everyone knows that sockets are platform specific and there is no
standard C++ API. You could at least point that out.

To the topic, I don't think that it is possible to close connections of a
different process. You can just kill those processes.
But a connection in CLOSE_WAIT just means that the other peer has already
closed the connection. If the child process is implemented correctly, it
just closes those connections and there won't be any zombie connections.

Tobi
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      12-11-2011
On Monday, December 12, 2011 1:15:07 AM UTC+8, Tobias Mller wrote:
> Leigh Johnston <(E-Mail Removed)> wrote:
> > On 11/12/2011 14:41, oshaer wrote:
> >> Hi Everybody
> >>
> >>
> >> I need to write a code that forcibly closes connections that are in
> >> CLOSE_WAIT status. It should run at a father process and constantly
> >> check the forked child processes(servers). I need this code to work on
> >> Unix/Linux, thus usage of WINAPI is not possible.
> >>
> >> My question is:
> >>
> >> 1) Should I use netstat through code and parse the result to learn
> >> which socket is in a CLOSE_WAIT situation?
> >>
> >> 2) Is there any C++ code that enables me to easily get socket status,
> >> given the file descriptor number?
> >>
> >> 3) If you have any other ideas/recommendations please share.

> >
> > Off-topic.
> >
> > HTH.
> >
> > /Leigh

>
> Not everyone knows that sockets are platform specific and there is no
> standard C++ API. You could at least point that out.
>
> To the topic, I don't think that it is possible to close connections of a
> different process. You can just kill those processes.
> But a connection in CLOSE_WAIT just means that the other peer has already
> closed the connection. If the child process is implemented correctly, it
> just closes those connections and there won't be any zombie connections.
>
> Tobi


This kind of trivial jobs in shell scripts that can be invoked by a C++ program
to spawn a process is really boring.

In POSIX compatible OSes the standard output can be directed to a file.


 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      12-11-2011
On Sun, 2011-12-11, oshaer wrote:
> I need to write a code that forcibly closes connections that are in
> CLOSE_WAIT status. It should run at a father process and constantly
> check the forked child processes(servers). I need this code to work on
> Unix/Linux, thus usage of WINAPI is not possible.
>
> My question is:
>
> 1) Should I use netstat through code and parse the result to learn
> which socket is in a CLOSE_WAIT situation?
>
> 2) Is there any C++ code that enables me to easily get socket status,
> given the file descriptor number?
>
> 3) If you have any other ideas/recommendations please share.


Like others mentioned, go seek advice in some Unix/Linux/POSIX group,
and/or refer to W R Stevens' books. Also mention there what the actual
problem is that you're trying to solve -- the way you're trying to do
it is almost certainly the wrong approach.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments