X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstreamsocket.cpp;h=79b08f4d91541854817d75f5f975f50444a21746;hb=2aab4004e71a2e5c773289e0be5e58aec6a8d339;hp=0f69111204af5ee0af783a158217ece68a7ecfa4;hpb=3970ee9cf7978c462390d49e083deb740d71c6fe;p=libs%2Fnet.git diff --git a/source/streamsocket.cpp b/source/streamsocket.cpp index 0f69111..79b08f4 100644 --- a/source/streamsocket.cpp +++ b/source/streamsocket.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspnet -Copyright © 2008 Mikkosoft Productions, Mikko Rasa -Distributed under the LGPL -*/ - #ifndef WIN32 #include #endif @@ -16,6 +9,19 @@ Distributed under the LGPL namespace Msp { namespace Net { +/** +Used by StreamListenSocket to construct a new socket from accept. +*/ +StreamSocket::StreamSocket(SocketHandle h, const SockAddr &paddr): + Socket(h, paddr), + connecting(false) +{ +#ifdef WIN32 + WSAEventSelect(handle, event, FD_READ|FD_CLOSE); +#endif + set_events(IO::P_INPUT); +} + /** Constructs a new StreamSocket. */ @@ -89,12 +95,12 @@ int StreamSocket::connect(const SockAddr &addr) if(connected) throw InvalidState("Socket is already connected"); - sockaddr sa; + sockaddr_storage sa; socklen_t size=addr.fill_sockaddr(sa); #ifdef WIN32 - int err=WSAConnect(handle, &sa, size, 0, 0, 0, 0); - if(err=SOCKET_ERROR) + int err=WSAConnect(handle, reinterpret_cast(&sa), size, 0, 0, 0, 0); + if(err==SOCKET_ERROR) { int err_code=WSAGetLastError(); if(err_code==WSAEWOULDBLOCK) @@ -107,7 +113,7 @@ int StreamSocket::connect(const SockAddr &addr) throw Exception(format("Unable to connect: %d", err_code)); } #else - int err=::connect(handle, &sa, size); + int err=::connect(handle, reinterpret_cast(&sa), size); if(err==-1) { if(errno==EINPROGRESS) @@ -124,32 +130,20 @@ int StreamSocket::connect(const SockAddr &addr) peer_addr=addr.copy(); delete local_addr; - size=sizeof(sockaddr); - getsockname(handle, &sa, &size); + size=sizeof(sockaddr_storage); + getsockname(handle, reinterpret_cast(&sa), &size); local_addr=SockAddr::create(sa); if(err==0) { connected=true; + set_events(IO::P_INPUT); signal_connect_finished.emit(0); } return (err==0)?0:1; } -/** -Used by StreamListenSocket to construct a new socket from accept. -*/ -StreamSocket::StreamSocket(SocketHandle h, const SockAddr &paddr): - Socket(h, paddr), - connecting(false) -{ -#ifdef WIN32 - WSAEventSelect(handle, event, FD_READ|FD_CLOSE); -#endif - set_events(IO::P_INPUT); -} - void StreamSocket::on_event(IO::PollEvent ev) { //cout<<"StreamSocket::on_event "<