Home Help Center

Question about souce codes "TcpEndpoint::acceptor"

OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
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? :confused: Consideration for reference number of smart pointer?

sorry for this trivial question.
Thanks in advance.

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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.
  • OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
    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
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    I don't think it's exactly the same -- the port might be different for instance.

    Benoit.
  • OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
    Thank you Benoit.
    Maybe the method "effectivePort()" is the key. I will test it further.


    OrNot
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    If you do not specify a port number, the operating system will choose one. endp returns an endpoint with that port number.
  • OrNotOrNot Member Bin.LiOrganization: GE HealthcareProject: Enterprise solution
    Oh yeah! :)
Sign In or Register to comment.