boost::asio::write only works on 1 of 2 boost::thread

boost::asio::write only works on 1 of 2 boost::thread

My program uses 2 ports simultaneously in separate threads but when the second thread writes on its own connection with its own port it seems to complete successfully but does not send anything, I verified this using process monitor.

I have tried a single boost::asio::io_service for both threads and one for either thread, I tried calling run() on 1 or both threads or not at all and none of that makes a difference.

Here are the relevant methods:

const int conport=48625;
const int vidport=48624;
boost::asio::io_service iosvc;
boost::asio::ip::tcp::socket consock(iosvc);
void ControlThread::operator()(NameEdit* nameptr){
    try{
        boost::asio::ip::tcp::endpoint endp(boost::asio::ip::tcp::v6(), conport);
        boost::asio::ip::tcp::acceptor acc(iosvc, endp);
        iosvc.run();
        boost::system::error_code ec;
acc:    acc.accept(consock, ec);
        boost::asio::streambuf buf;
        auto n=boost::asio::read(consock, buf, boost::asio::transfer_exactly(1), ec);
        buf.commit(n);
        if(BufCast(buf)[0]!=2){
            consock.close();
            goto acc;
        }
        boost::asio::write(consock, boost::asio::buffer((char*)2, 1), boost::asio::transfer_exactly(1), ec);
        ConMain(nameptr);
    }catch(std::exception& ex){
        MessageBoxExA(NULL, (LPCSTR)ex.what(), "Error", MB_ICONEXCLAMATION, 0);
    }
}

boost::asio::ip::tcp::socket vidsock(iosvc);
void VideoThread::operator()(){
    try{
        boost::asio::ip::tcp::endpoint endp(boost::asio::ip::tcp::v6(), vidport);
        boost::asio::ip::tcp::acceptor acc(iosvc, endp);
        iosvc.run();
        boost::system::error_code ec;
acc:    acc.accept(vidsock, ec);
        boost::asio::streambuf buf;
        auto n=boost::asio::read(vidsock, buf, boost::asio::transfer_exactly(1), ec);
        buf.commit(n);
        if(BufCast(buf)[0]!=2){
            vidsock.close();
            goto acc;
        }
        boost::asio::write(vidsock, boost::asio::buffer((char*)2, 1), boost::asio::transfer_exactly(1), ec); // THIS write does not send
        VideoThread::VidMain();
    }catch(std::exception& ex){
        MessageBoxExA(NULL, (LPCSTR)ex.what(), "Error", MB_ICONEXCLAMATION, 0);
    }
}

I'm using boost 1.54 and Intel compiler v14 the visual studio 2012 project is an MFC executable.

10 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Woops I meant Visual studio 2010, why cant I edit my post?

Maybe your problem is not directly related to Intel Compiler?I suppose that the underlying networking stack which is called by boost::asio should blamed for. 

Btw try to use netmon it gives more detailed information about the process networking activity including connection setup and tear down.

I didn't say the Intel compiler is the problem where else could I post this, I know theres something I'm not doing right I need someone to tell me what it is.

Quote:

commanderlake wrote:

I didn't say the Intel compiler is the problem where else could I post this, I know theres something I'm not doing right I need someone to tell me what it is.

I do not really know where you can post this.May you try posting your question on boost library forum if one exists.

I was thinking on another possibility on how to investigate such issue.There is option to use debugger and try execution of your code with logexts logging extension in order to find which dll is beign called by boost::asio library.Next putting breakpoint on function call to probably Winsock library could hopefully reveal the culprit.

Thanks but I'm still relatively new to C++ as I do C# mostly, I need clear instructions.

We can do it by sending private messages,but I encourage you still to search boost forums for the solution.

I cant find the boost forum.

Look I do not use boost and I do not do any network related programming so I cannot offer any serious help,but if you are interested on how to troubleshoot such a problem please contact me privately(send private message).

Connectez-vous pour laisser un commentaire.