#3 Bug in TCPSession::TCPSession(..)

Common_Libraries
closed
nobody
Library (32)
5
2005-08-31
2005-08-12
Anonymous
No

I derived a class from TCPSession

=================
class mySession : public ost::TCPSession {
mySession(const InetHostAddress &server, tpport_t
port) : TCPSession( server,port) {}
}
=================

As you can see, the TCPSession constructor being
used is not the one that accepts a socket, rather just a
server address.

I found that in order to actually get this to work, I
needed to add a line of code to the TCPSession
constructor in order to open a socket (see below).

=================
TCPSession::TCPSession(const IPV4Host &ia,
tpport_t port, size_t size, int
pri, size_t stack) :
Thread(pri, stack), TCPStream(IPV4)
{
setCompletion(false);
setError(false);
allocate(size);

/// I NEEDED TO OPEN A SOCKET HERE
so=socket(AF_INET,SOCK_STREAM,0);

size\_t i;
for\(i = 0 ; i < ia.getAddressCount\(\); i++\)

=================

It seems like "so" does not get properly initialized on its
own.

Guy

Discussion

  • David Sugar

    David Sugar - 2005-08-14
    • milestone: --> Common_Libraries
    • assigned_to: nobody --> dyfet
     
  • David Sugar

    David Sugar - 2005-08-14

    Logged In: YES
    user_id=217

    Hmm...ultimately, the socket should be initialized from within TCPStream....

    Do you mean to do Thread(pri, stack), TCPStream(IPV4) or do you mean:

    Thread(pri,stack), TCPStream(ia, port, size) ???

     
  • Guy Shechter

    Guy Shechter - 2005-08-15

    Logged In: YES
    user_id=1058524

    It does appear that changing TCPStream(IPV4) to TCPStream
    (ia,port,size) does the trick.

    Referencing commoncpp-1.3.17: this modification should be
    applied at line 3175 of socket.cpp.

     
  • David Sugar

    David Sugar - 2005-08-15

    Logged In: YES
    user_id=217

    Ah, this explanation helps.

    TCPSession is meant for two purposes: to create a thread for a socket
    accepted from TCPSocket, or to create a thread for a client TCP session.
    The socket should only be created when the TCPSession is being
    "connected" to a remote listening socket, and this does not occur in the
    constructor because connecting is considered a blocking operation. This
    way the potentially blocking connection will occur in the new thread rather
    than the thread constructing the object. It sounds like your use falls outside
    these two original expectations. Are you using TCPStream to "bind" a
    listening socket? Given that a bound and listening tcp socket never itself
    moves data, I did not think it appropriate to make a stream class for
    TCPSocket.

     
  • David Sugar

    David Sugar - 2005-08-15

    Logged In: YES
    user_id=217

    Or of course, you can do the other constructor, that accepts a host and port,
    and also have the risk of potentially blocking during construction...

     
  • Guy Shechter

    Guy Shechter - 2005-08-26

    Logged In: YES
    user_id=1058524

    Alternatively, I found that commenting out (~socket.cpp: 3200

    // if(WSAGetLastError() == WSAEISCONN)

    and using

    if(WSAGetLastError() == WSAEWOULDBLOCK)

    fixed the connection issues i was having.

     
  • David Sugar

    David Sugar - 2005-08-27
    • assigned_to: dyfet --> conradpino
     
  • David Sugar

    David Sugar - 2005-08-30
    • status: open --> pending
     
  • Conrad T. Pino

    Conrad T. Pino - 2005-08-31
    • status: pending --> open
    • assigned_to: conradpino --> nobody
     
  • David Sugar

    David Sugar - 2005-08-31

    Logged In: YES
    user_id=217

    socket.cpp changed for 1.3.19

     
  • David Sugar

    David Sugar - 2005-08-31
    • status: open --> closed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks