Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #12345 > unrolled thread

Getting the status of a socket through code

Started byoshaer <oshaer@gmail.com>
First post2011-12-11 06:41 -0800
Last post2011-12-11 22:54 +0000
Articles 6 — 6 participants

Back to article view | Back to comp.lang.c++


Contents

  Getting the status of a socket through code oshaer <oshaer@gmail.com> - 2011-12-11 06:41 -0800
    Re: Getting the status of a socket through code Leigh Johnston <leigh@i42.co.uk> - 2011-12-11 14:42 +0000
      Re: Getting the status of a socket through code Tobias Müller <troplin@bluewin.ch> - 2011-12-11 17:15 +0000
        Re: Getting the status of a socket through code 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-11 09:46 -0800
    Re: Getting the status of a socket through code Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-11 10:52 -0500
    Re: Getting the status of a socket through code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-12-11 22:54 +0000

#12345 — Getting the status of a socket through code

Fromoshaer <oshaer@gmail.com>
Date2011-12-11 06:41 -0800
SubjectGetting the status of a socket through code
Message-ID<6babe985-31c8-48a7-807c-aebc1fd9c242@i8g2000vbh.googlegroups.com>
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.

[toc] | [next] | [standalone]


#12346

FromLeigh Johnston <leigh@i42.co.uk>
Date2011-12-11 14:42 +0000
Message-ID<LqGdnf6bufzrXHnTnZ2dnUVZ8gCdnZ2d@giganews.com>
In reply to#12345
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

[toc] | [prev] | [next] | [standalone]


#12353

FromTobias Müller <troplin@bluewin.ch>
Date2011-12-11 17:15 +0000
Message-ID<1917565489345315192.614698troplin-bluewin.ch@news.aioe.org>
In reply to#12346
Leigh Johnston <leigh@i42.co.uk> 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

[toc] | [prev] | [next] | [standalone]


#12354

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-11 09:46 -0800
Message-ID<23346451.1985.1323625598083.JavaMail.geo-discussion-forums@prmw6>
In reply to#12353
On Monday, December 12, 2011 1:15:07 AM UTC+8, Tobias Müller wrote:
> Leigh Johnston <le...@i42.co.uk> 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.

  

[toc] | [prev] | [next] | [standalone]


#12350

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-12-11 10:52 -0500
Message-ID<jc2jje$j82$1@dont-email.me>
In reply to#12345
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

[toc] | [prev] | [next] | [standalone]


#12370

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-12-11 22:54 +0000
Message-ID<slrnjead48.q8l.grahn+nntp@frailea.sa.invalid>
In reply to#12345
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   .

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web