strange socket behavior - Linux

This is a discussion on strange socket behavior - Linux ; I'm having a 'problem' I'm not sure how to deal with. I have a client/server system that makes high reuse of sockets. I use a table to keep state information, and use the socket fds as the index into this ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: strange socket behavior

  1. strange socket behavior

    I'm having a 'problem' I'm not sure how to deal with. I have a
    client/server system that makes high reuse of sockets. I use a table
    to keep state information, and use the socket fds as the index into
    this table. As the sockets open and close, some sockets are re-used,
    but the trend is allways to get higher numbered fds for a socket.
    Eventually the fd is greater than the size of the table. This is
    regardless of how large I make my table. Of course, periodically I
    check all open sockets, and if there has been no activity for some
    period of time, I close the socket, but for the most part, the lower
    numbers never get re-used. Yes, I can hash the fd to get an offset,
    but I'm wondering why I don't just get the lower, unused fd number.

    tia,
    Tom

    please reply at
    tgreen.at.nospam.contentwatch.nospam.com
    to email remove the each .nospam, and convert at appropriately


  2. Re: strange socket behavior


    tomg_tt wrote:

    > I'm having a 'problem' I'm not sure how to deal with. I have a
    > client/server system that makes high reuse of sockets. I use a table
    > to keep state information, and use the socket fds as the index into
    > this table. As the sockets open and close, some sockets are re-used,
    > but the trend is allways to get higher numbered fds for a socket.
    > Eventually the fd is greater than the size of the table. This is
    > regardless of how large I make my table. Of course, periodically I
    > check all open sockets, and if there has been no activity for some
    > period of time, I close the socket, but for the most part, the lower
    > numbers never get re-used. Yes, I can hash the fd to get an offset,
    > but I'm wondering why I don't just get the lower, unused fd number.


    On Linux, 'socket' and 'accept' will *always* give you the lowest
    unused non-negative integer. If you get 5, that means zero through four
    were all in use as sockets or files.

    There are a few possibilities, but one may be that your program has a
    file descriptor or socket leak. It could be in completely unrelated
    code to the code you think you have a problem with. A missing 'close',
    'fclose', or 'pclose' could be the culprit.

    Every call to 'socket' or 'accept' must have a matching call to
    'close', even if the connection itself is already the closed, the
    descriptor still references it.

    DS


  3. Re: strange socket behavior

    You can use netstat -np to check the socket you have already opened.
    Maybe something is leak.

    ABAI

    On 11月11日, 上午7时33分, "tomg_tt" wrote:
    > I'm having a 'problem' I'm not sure how to deal with. I have a
    > client/server system that makes high reuse of sockets. I use a table
    > to keep state information, and use the socket fds as the index into
    > this table. As the sockets open and close, some sockets are re-used,
    > but the trend is allways to get higher numbered fds for a socket.
    > Eventually the fd is greater than the size of the table. This is
    > regardless of how large I make my table. Of course, periodically I
    > check all open sockets, and if there has been no activity for some
    > period of time, I close the socket, but for the most part, the lower
    > numbers never get re-used. Yes, I can hash the fd to get an offset,
    > but I'm wondering why I don't just get the lower, unused fd number.
    >
    > tia,
    > Tom
    >
    > please reply at
    > tgreen.at.nospam.contentwatch.nospam.com
    > to email remove the each .nospam, and convert at appropriately



+ Reply to Thread