Subject: [Boost-bugs] [Boost C++ Libraries] #5157: Assign native socket problem
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-03 23:25:47
#5157: Assign native socket problem
----------------------------------+-----------------------------------------
Reporter: a.pacek@⦠| Owner: chris_kohlhoff
Type: Bugs | Status: new
Milestone: | Component: asio
Version: Boost 1.45.0 | Severity: Problem
Keywords: native socket assign |
----------------------------------+-----------------------------------------
Hi
I'm trying to duplicate accepted/opened socket and pass them to other
process.
It works fine under linux. But under Windows I can't assign
this native socket to boost::asio::ip::tcp::socket.
When I try to assign opened native socket to boost socket object
s.assign(boost::asio::ip::tcp::v4(), socketDup)
throws me exception: "The parameter is incorrect".
Even if I try to duplicate socket and use them in the same process.
I still got this exception.
The line inside boost throws this exception:
boost_1_45_0\boost\asio\detail\impl\win_iocp_io_service.ipp:
{{{
boost::system::error_code win_iocp_io_service::register_handle(
HANDLE handle, boost::system::error_code& ec)
{
if (::CreateIoCompletionPort(handle, iocp_.handle, 0, 0) == 0)
//this function failed
{
DWORD last_error = ::GetLastError();
ec = boost::system::error_code(last_error,
boost::asio::error::get_system_category());
}
else
{
ec = boost::system::error_code();
}
return ec;
}
}}}
I'm using: VC++ 2008 / Win7
What am I doing wrong?
How can I resolve this problem?
Thanks for help.
Example code:
{{{
boost::asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), m_nPort));
std::cout << "Waiting for connection..." << std::endl;
tcp::socket socket(io_service);
acceptor.accept(socket);
std::cout << "connection accepted" << std::endl;
#ifdef _WIN32
WSAPROTOCOL_INFO pi;
WSADuplicateSocket(socket.native(), get_current_process_id(), &pi);
SOCKET socketDup = WSASocket(pi.iAddressFamily/*AF_INET*/,
pi.iSocketType/*SOCK_STREAM*/,
pi.iProtocol/*IPPROTO_TCP*/, &pi, 0, 0);
char sText[] = "I can use my duplicated socket via WinApi!\r\n";
int nRet = send(socketDup, sText, strlen(sText), 0);
#else
//linux
int socketDup = dup(socket.native());
#endif
try
{
tcp::socket s(io_service);
s.assign(boost::asio::ip::tcp::v4(), socketDup); //this throws
exception under Windows
//I can't use my socket via boost lib
s.send(boost::asio::buffer("Not work\r\n"));
}
catch(std::exception &e)
{
std::cerr << e.what() << std::endl; //"The parameter is incorrect"
exception
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5157> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC