[Boost-users] boost asio tcp::socket assign

238 views
Skip to first unread message

Lloyd

unread,
Dec 30, 2010, 3:41:18 AM12/30/10
to Boost Users
Hi,

I have a boost::asio::ip::tcp::socket variable (reference) in a class,
and it is initialized at the object construction time. At a later time
I need to assign a new socket to this "socket reference variable". I
think boost::assign is meant for that. But when I use assign, get the
following error... (or is there any other method available?)


.....cannot convert parameter 2 from 'boost::asio::ip::tcp::socket' to
'const boost::asio::detail::win_iocp_socket_service<Protocol>::native_type
&'


The code snippet is as follows...

class MyClass
{
....
.....
private:
tcp::socket& Socket;
}

void MyClass::SetSocket(tcp::socket& s)
{
Socket.assign(boost::asio::ip::tcp::v4(),s);
}

What could be the reason?

Thanks in advance,
Lloyd
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Igor R

unread,
Dec 30, 2010, 3:54:04 AM12/30/10
to boost...@lists.boost.org
> I have a boost::asio::ip::tcp::socket variable (reference) in a class,
> and it is initialized at the object construction time. At a later time
> I need to assign a new socket to this "socket reference variable". I
> think boost::assign is meant for that. But when I use assign, get the
> following error... (or is there any other method available?)
>
>
> .....cannot convert parameter 2 from 'boost::asio::ip::tcp::socket' to
> 'const boost::asio::detail::win_iocp_socket_service<Protocol>::native_type
> &'
>
>
> The code snippet is as follows...
>
> class MyClass
> {
> ....
> .....
>  private:
>         tcp::socket& Socket;
> }
>
> void MyClass::SetSocket(tcp::socket& s)
> {
>        Socket.assign(boost::asio::ip::tcp::v4(),s);
> }


assign() sets a native socket handler to the tcp::socket object. I.e.
if you open a socket by means of some native API, then you can
assign() this native socket handle to tcp::socket.

Lloyd

unread,
Dec 30, 2010, 4:01:57 AM12/30/10
to boost...@lists.boost.org
Thanks Igor,

then is there any method/operator (=) available in asio to assign a
socket to another socket?

Thanks a lot,
Lloyd

Igor R

unread,
Dec 30, 2010, 5:35:48 AM12/30/10
to boost...@lists.boost.org
> then is there any method/operator (=) available in asio to assign a
> socket to another socket?

No, socket is non-copyable. If you have to create and pass the socket
object to from outside, you can define a smart-ptr to tcp::socket in
your class, or an optional<tcp::socket>.

Lloyd

unread,
Jan 1, 2011, 1:10:03 AM1/1/11
to boost...@lists.boost.org
Thanks Igor. Wish you (all) a very happy new year...
Reply all
Reply to author
Forward
0 new messages