Socket::~Socket()
{
- close();
+ signal_flush_required.emit();
+#ifdef WIN32
+ closesocket(handle);
+ CloseHandle(event);
+#else
+ ::close(handle);
+#endif
+
+ delete local_addr;
+ delete peer_addr;
}
void Socket::set_block(bool b)
local_addr = addr.copy();
}
-void Socket::close()
-{
- if(handle==MSP_NET_INVALID_SOCKET_HANDLE)
- return;
-
- set_events(IO::P_NONE);
-
- signal_flush_required.emit();
-#ifdef WIN32
- closesocket(handle);
- CloseHandle(event);
-#else
- ::close(handle);
-#endif
- handle = MSP_NET_INVALID_SOCKET_HANDLE;
- connected = false;
- signal_closed.emit();
-
- delete local_addr;
- local_addr = 0;
- delete peer_addr;
- peer_addr = 0;
-}
-
void Socket::set_timeout(const Time::TimeDelta &timeout)
{
#ifndef WIN32
void Socket::check_state(bool conn) const
{
- if(handle==MSP_NET_INVALID_SOCKET_HANDLE)
- throw bad_socket_state("socket is closed");
if(conn && !connected)
throw bad_socket_state("not connected");
}
type. */
virtual int connect(const SockAddr &) = 0;
- /// Closes the socket. Most operations will throw an exception after this.
- void close();
-
void set_timeout(const Time::TimeDelta &);
const SockAddr &get_local_address() const;
const SockAddr &get_peer_address() const;