@@ -217,15 +217,20 @@ void CurlMultiManager::check_multi_info() {
217217void CurlMultiManager::start_socket_monitor (SocketInfo* socket_info,
218218 const int action) {
219219 if (!socket_info->handle ) {
220- // Create handle for this socket
220+ // Create tcp::socket and assign the native socket handle
221+ // This works cross-platform (Windows and POSIX)
221222 socket_info->handle = std::make_shared<SocketHandle>(executor_);
222- #ifdef _WIN32
223- // On Windows, we need to cast the socket to HANDLE for stream_handle
224- socket_info->handle ->assign (reinterpret_cast <HANDLE >(socket_info->sockfd ));
225- #else
226- // On POSIX, we can assign the socket descriptor directly
227- socket_info->handle ->assign (socket_info->sockfd );
228- #endif
223+
224+ // Assign the CURL socket to the ASIO socket
225+ // tcp::socket::assign works with native socket handles on both platforms
226+ boost::system::error_code ec;
227+ socket_info->handle ->assign (boost::asio::ip::tcp::v4 (), socket_info->sockfd , ec);
228+
229+ if (ec) {
230+ std::cerr << " Failed to assign socket: " << ec.message () << std::endl;
231+ socket_info->handle .reset ();
232+ return ;
233+ }
229234 }
230235
231236 // Check if action has changed
@@ -255,7 +260,7 @@ void CurlMultiManager::start_socket_monitor(SocketInfo* socket_info,
255260 }
256261
257262 handle->async_wait (
258- SocketHandle ::wait_read,
263+ boost::asio::ip::tcp::socket ::wait_read,
259264 [weak_self, sockfd, weak_handle, weak_read_handler](
260265 const boost::system::error_code& ec) {
261266 // If operation was canceled or had an error, don't re-register
@@ -298,7 +303,7 @@ void CurlMultiManager::start_socket_monitor(SocketInfo* socket_info,
298303 }
299304
300305 handle->async_wait (
301- SocketHandle ::wait_write,
306+ boost::asio::ip::tcp::socket ::wait_write,
302307 [weak_self, sockfd, weak_handle, weak_write_handler](
303308 const boost::system::error_code& ec) {
304309 // If operation was canceled or had an error, don't re-register
0 commit comments