Invalid arguments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Invalid arguments

Boost - Dev mailing list
I’ve the following function but i get invalid arguments error , can please
someone tell me where’s this invalid param or argument :

int Asio_Send_Pck(int iSendt,int Lsocket,char * Lbuff,int Len)

{

    session* iTempSession = reinterpret_cast<session*>(Lsocket);

    boost::asio::async_write(iTempSession->socket() ,

                              boost::asio::buffer(Lbuff, Len),

                              boost::bind(&session::handle_write,

                              iTempSession,

                              boost::asio::placeholders::error,

                              iTempSession->data,

                              iSendt

                              ));

    return 0;

};

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Invalid arguments

Boost - Dev mailing list
On 12/07/2018 20:12, randy wrote:
> I’ve the following function but i get invalid arguments error , can please
> someone tell me where’s this invalid param or argument :

Usage queries belong in the boost-users mailing list, not this one.  You
should also indicate the library in the subject, eg. [asio].

> int Asio_Send_Pck(int iSendt,int Lsocket,char * Lbuff,int Len)
> {
>      session* iTempSession = reinterpret_cast<session*>(Lsocket);

This is poor design (and may be UB on some platforms).  You should use a
pimpl or opaque pointer instead.  (Note that there are ways to do this
even if you need to declare a pure C API.)

>      boost::asio::async_write(iTempSession->socket() ,
>                                boost::asio::buffer(Lbuff, Len),
>                                boost::bind(&session::handle_write,
>                                iTempSession,
>                                boost::asio::placeholders::error,
>                                iTempSession->data,
>                                iSendt
>                                ));

There are lots of things that could be wrong with this.  Since you
haven't even posted the actual error you're getting or other details
about objects referenced in this call it's hard to tell for sure.

But at least one issue is that in order to conform to Asio's
WriteHandler concept you need to include
boost::asio::placeholders::bytes_transferred in your handler arguments.

See
https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/reference/WriteHandler.html.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost