Archived
This forum has been archived. Please start a new discussion on GitHub.
Question about souce codes "TcpEndpoint::acceptor"
in Help Center
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.
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?

sorry for this trivial question.
Thanks in advance.
0
Comments
-
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.0 -
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---OrNot0 -
I don't think it's exactly the same -- the port might be different for instance.
Benoit.0 -
Thank you Benoit.
Maybe the method "effectivePort()" is the key. I will test it further.
OrNot0 -
If you do not specify a port number, the operating system will choose one. endp returns an endpoint with that port number.0
-
Oh yeah!0