
Out of curiousity (reading somebody comment here regarding socket calls) I looked into the asio library and found the following example code below. My question is: What is the use of the socket object created in the first line? I think this line must always be followed by some more code. Because of this it does not make sense, that a library exports this functionality. boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }

On Mon, Oct 26, 2009 at 10:30 PM, Peter Foelsche <peter_foelsche@agilent.com> wrote:
Out of curiousity (reading somebody comment here regarding socket calls) I looked into the asio library and found the following example code below. My question is: What is the use of the socket object created in the first line?
Doesn't the third line use it?
I think this line must always be followed by some more code. Because of this it does not make sense, that a library exports this functionality.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Olaf

"Olaf van der Spek" <olafvdspek@gmail.com> wrote in message news:b2cc26e40910270119o6d461aa6x29607f0362eac6e0@mail.gmail.com...
What is the use of the socket object created in the first line?
Doesn't the third line use it?
The point is that there must be always something following this statement -- by itself it does not make any sense. Thus this code could have been combined with any possible following code.

Peter Foelsche wrote:
"Olaf van der Spek" <olafvdspek@gmail.com> wrote in message news:b2cc26e40910270119o6d461aa6x29607f0362eac6e0@mail.gmail.com...
What is the use of the socket object created in the first line?
Doesn't the third line use it?
The point is that there must be always something following this statement -- by itself it does not make any sense. Thus this code could have been combined with any possible following code.
Two-stage construction is a common, if somewhat awkward idiom. I can imagine -- but don't know -- that this was done to give the option of not getting exceptions when they aren't wanted, though I know you find that disturbing. Perhaps the constructor can be overloaded to allow both approaches? _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On Tue, Oct 27, 2009 at 5:48 PM, Peter Foelsche <peter_foelsche@agilent.com> wrote:
"Olaf van der Spek" <olafvdspek@gmail.com> wrote in message news:b2cc26e40910270119o6d461aa6x29607f0362eac6e0@mail.gmail.com...
What is the use of the socket object created in the first line?
Doesn't the third line use it?
The point is that there must be always something following this statement -- by itself it does not make any sense. Thus this code could have been combined with any possible following code.
Is the code that follows it always the same? Olaf

"Olaf van der Spek" <olafvdspek@gmail.com> wrote in message news:b2cc26e40910271142y1edebfbqdf321627bffd1e15@mail.gmail.com...
What is the use of the socket object created in the first line?
Doesn't the third line use it?
The point is that there must be always something following this statement -- by itself it does not make any sense. Thus this code could have been combined with any possible following code.
Is the code that follows it always the same?
The number of use cases is limited. Here are some of them: * connect to a well known address (client) * bind to a well known address -- create listening socket (server)

Am Dienstag, den 27.10.2009, 20:10 +0100 schrieb "Peter Foelsche" <peter_foelsche@agilent.com>:
"Olaf van der Spek" <olafvdspek@gmail.com> wrote in message news:b2cc26e40910271142y1edebfbqdf321627bffd1e15@mail.gmail.com...
What is the use of the socket object created in the first line?
Doesn't the third line use it?
The point is that there must be always something following this statement -- by itself it does not make any sense. Thus this code could have been combined with any possible following code.
Is the code that follows it always the same?
The number of use cases is limited. Here are some of them:
* connect to a well known address (client) * bind to a well known address -- create listening socket (server)
So what do you propose? An asynchronous constructor for socket? Daniel
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

"Daniel Pfeifer" <daniel@pfeifer-mail.de> wrote in message news:6d2cdc7bcae533b0939b0137b5b4c0af-EhVcX1dJTQZXRw0RBgwNVDBXdh9XVlpBXkJHHF5ZWC9QVUYKXlZoAFFSQ11aLkQAWlxfR1lSWQg=-webmailer2@server07.webmailer.hosteurope.de...
The number of use cases is limited. Here are some of them:
* connect to a well known address (client) * bind to a well known address -- create listening socket (server)
So what do you propose? An asynchronous constructor for socket?
Nope I did not propose anything like this. For the two use-cases I mentioned, we would need two separate classes -- with a constructor and destructor and a method to return the created file-descriptor/socket-handle.
participants (4)
-
Daniel Pfeifer
-
Olaf van der Spek
-
Peter Foelsche
-
Stewart, Robert