Boost logo

Boost Users :

Subject: Re: [Boost-users] [ASIO] async_accept : Error m_val 1.
From: Viatcheslav.Sysoltsev_at_[hidden]
Date: 2011-03-10 09:42:30


On Thu, 10 Mar 2011 13:47:46 +0100, Cyprien DIOT <cyprien.diot_at_[hidden]>
wrote:

>
> I've made unit test for this problem.
>
> Server.h:
>
> #pragma once
>
>
> #include <boost/thread/thread.hpp>
> #include <boost/asio.hpp>
> #include <boost/array.hpp>
> #include <iostream>
>
> class Server
> {
> public:
> AssistGui(boost::asio::io_service &);
> ~AssistGui(void);
>
> void accept(const boost::system::error_code& e);
> void sendMsg(const char *msg, unsigned int size);
>
> private:
> boost::asio::io_service &io;
> boost::asio::ip::tcp::socket _client;
> boost::asio::ip::tcp::acceptor _acceptor;
>
> };
>
> Server.cpp:
>
> #include "Server.h"
>
> using boost::asio::ip::tcp;
>
> Server::Server(boost::asio::io_service &ios) : io(ios), _client(ios),
> _acceptor(ios, tcp::endpoint(tcp::v4(), 14242))
> {
> _acceptor.async_accept(_client, boost::bind(&Server::accept, this,
> boost::asio::placeholders::error));
> }
>
> void Server::sendMsg(const char *msg, unsigned int size)
> {
>
> }
> Server::~Server(void)
> {
> }
>
> void Server::accept(const boost::system::error_code& e)
> {
> // same error :-( : "Already open"
> }
>
> int main()
> {
> boost::asio::io_service ios;
>
> Server s(ios);
> ios.run();
> }
>
>
> The error is still the same "Already open".
> _WIN32_WINNT=0x0501 is defined.
> I tried to change port.
> No warnings at program compilation.
> Can you help me?
>
> Thank you
>
> Cyprien DIOT
>

Hi Cyprien,

as far as I remember from socket programming, if you open a socket without
REUSE option, it is marked busy even after releasing for a some time
afterwards depending on your kernel implementation. Probably if you reboot
or wait some time, your testcase will work but again only once. Try
setting REUSE flag for your socket to check if it helps.

-- Slava


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net