+ m_detected = wxSOCKET_LOST_FLAG;
+}
+
+/*
+ * Sets the timeout for blocking calls. Time is expressed in
+ * milliseconds.
+ */
+void wxSocketImpl::SetTimeout(unsigned long millis)
+{
+ m_timeout.tv_sec = (millis / 1000);
+ m_timeout.tv_usec = (millis % 1000) * 1000;
+}
+
+void wxSocketImpl::NotifyOnStateChange(wxSocketNotify event)
+{
+ m_wxsocket->OnRequest(event);
+}
+
+/* Address handling */
+
+/*
+ * Set or get the local or peer address for this socket. The 'set'
+ * functions return wxSOCKET_NOERROR on success, an error code otherwise.
+ * The 'get' functions return a pointer to a GAddress object on success,
+ * or NULL otherwise, in which case they set the error code of the
+ * corresponding socket.
+ *
+ * Error codes:
+ * wxSOCKET_INVSOCK - the socket is not valid.
+ * wxSOCKET_INVADDR - the address is not valid.
+ */
+wxSocketError wxSocketImpl::SetLocal(GAddress *address)
+{
+ /* the socket must be initialized, or it must be a server */
+ if (m_fd != INVALID_SOCKET && !m_server)
+ {
+ m_error = wxSOCKET_INVSOCK;
+ return wxSOCKET_INVSOCK;
+ }
+
+ /* check address */
+ if (address == NULL || address->m_family == wxSOCKET_NOFAMILY)
+ {
+ m_error = wxSOCKET_INVADDR;
+ return wxSOCKET_INVADDR;
+ }
+
+ if (m_local)
+ GAddress_destroy(m_local);
+
+ m_local = GAddress_copy(address);
+
+ return wxSOCKET_NOERROR;
+}
+
+wxSocketError wxSocketImpl::SetPeer(GAddress *address)
+{
+ /* check address */
+ if (address == NULL || address->m_family == wxSOCKET_NOFAMILY)
+ {
+ m_error = wxSOCKET_INVADDR;
+ return wxSOCKET_INVADDR;
+ }
+
+ if (m_peer)
+ GAddress_destroy(m_peer);
+
+ m_peer = GAddress_copy(address);
+
+ return wxSOCKET_NOERROR;
+}
+
+GAddress *wxSocketImpl::GetLocal()
+{
+ GAddress *address;
+ wxSockAddr addr;
+ WX_SOCKLEN_T size = sizeof(addr);
+ wxSocketError err;
+
+ /* try to get it from the m_local var first */
+ if (m_local)
+ return GAddress_copy(m_local);
+
+ /* else, if the socket is initialized, try getsockname */
+ if (m_fd == INVALID_SOCKET)
+ {
+ m_error = wxSOCKET_INVSOCK;
+ return NULL;
+ }
+
+ if (getsockname(m_fd, (sockaddr*)&addr, &size) == SOCKET_ERROR)
+ {
+ m_error = wxSOCKET_IOERR;
+ return NULL;
+ }
+
+ /* got a valid address from getsockname, create a GAddress object */
+ if ((address = GAddress_new()) == NULL)
+ {
+ m_error = wxSOCKET_MEMERR;
+ return NULL;
+ }
+
+ if ((err = _GAddress_translate_from(address, (sockaddr*)&addr, size)) != wxSOCKET_NOERROR)
+ {
+ GAddress_destroy(address);
+ m_error = err;
+ return NULL;
+ }
+
+ return address;
+}
+
+GAddress *wxSocketImpl::GetPeer()
+{
+ /* try to get it from the m_peer var */
+ if (m_peer)
+ return GAddress_copy(m_peer);