Results 1 to 7 of 7

Thread: Question about souce codes "TcpEndpoint::acceptor"

  1. #1
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181

    Question about souce codes "TcpEndpoint::acceptor"

    hi,there,
    In the TcpEndpoint.cpp file,

    AcceptorPtr
    IceInternal::TcpEndpoint::acceptor(EndpointPtr& endp) const
    {
    TcpAcceptor* p = new TcpAcceptor(_instance, _host, _port);

    ------------- ?????-------------------------------------------
    endp = new TcpEndpoint(_instance, _host, p->effectivePort(), _timeout, _compress);
    ---------------------------------------------------------


    return p;
    }


    I can't understand the lines with "new" . why need such codes? Consideration for reference number of smart pointer?

    sorry for this trivial question.
    Thanks in advance.

  2. #2
    benoit's Avatar
    benoit is online now ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Hi,

    The "endp" argument is passed by reference and is used as a return value for the accept() method. The use of a smart pointer ensures that the caller won't have to take care of the deallocation of the TcpEndpoint object.

    I hope this is clearer!

    Benoit.

  3. #3
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181
    hi, Benoit,
    Sorry for my poor expression about my question. I mean, why need to allocate a new TcpEndpoint here? I traced into the code and found that the members of the new TcpEndpoint seem to have the same values as the one passed in by "EndpointPtr& endp" except the address and the ref. Why not use the original TcpEndoint in the accept() method ?
    There must be some thing out of my understanding. Hope getting your help.

    Best Regards---OrNot

  4. #4
    benoit's Avatar
    benoit is online now ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    I don't think it's exactly the same -- the port might be different for instance.

    Benoit.

  5. #5
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181
    Thank you Benoit.
    Maybe the method "effectivePort()" is the key. I will test it further.


    OrNot

  6. #6
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    If you do not specify a port number, the operating system will choose one. endp returns an endpoint with that port number.

  7. #7
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181
    Oh yeah!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 01-31-2011, 07:32 PM
  2. Question Regarding Slice Interface "Best practices"
    By MMOInteractive in forum Help Center
    Replies: 1
    Last Post: 11-02-2010, 01:16 PM
  3. Replies: 1
    Last Post: 06-09-2009, 10:53 PM
  4. Replies: 1
    Last Post: 01-28-2009, 06:15 AM
  5. Replies: 4
    Last Post: 10-26-2006, 11:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •