* wxSocket seems to work with the async requester turned off.

Two things to fix:
       * async requester bug
       * GTK/GLIB idle loop wake up
  URL/HTTP/FTP/SocketServer/SocketClient seems to work (well, they work
  on my computer).


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1999-05-23 16:09:45 +00:00
parent 6bc8a1c80b
commit 48da7d0ba8
3 changed files with 34 additions and 17 deletions

View File

@@ -553,8 +553,8 @@ bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
wxPendingEventsLocker->Leave(); wxPendingEventsLocker->Leave();
#ifdef __WXGTK__ #ifdef __WXGTK__
if (g_isIdle) // if (g_isIdle)
wxapp_install_idle_handler(); // wxapp_install_idle_handler();
#endif #endif
return TRUE; return TRUE;

View File

@@ -114,6 +114,7 @@ void SocketWaiter::ProcessReadEvent()
m_socket->OnRequest(wxSocketBase::EVT_READ); m_socket->OnRequest(wxSocketBase::EVT_READ);
} else { } else {
m_socket->OnRequest(wxSocketBase::EVT_LOST); m_socket->OnRequest(wxSocketBase::EVT_LOST);
m_internal->ReleaseData(); // In that case, we mustn't forget to unlock the mutex.
Exit(NULL); Exit(NULL);
} }
} }
@@ -141,6 +142,8 @@ void *SocketWaiter::Entry()
FD_ZERO(&sockrd_set); FD_ZERO(&sockrd_set);
FD_ZERO(&sockwr_set); FD_ZERO(&sockwr_set);
m_internal->AcquireData();
if ((m_socket->NeededReq() & READ_MASK) != 0) if ((m_socket->NeededReq() & READ_MASK) != 0)
FD_SET(m_fd, &sockrd_set); FD_SET(m_fd, &sockrd_set);
if ((m_socket->NeededReq() & WRITE_MASK) != 0) if ((m_socket->NeededReq() & WRITE_MASK) != 0)
@@ -156,6 +159,8 @@ void *SocketWaiter::Entry()
if (FD_ISSET(m_fd, &sockwr_set)) if (FD_ISSET(m_fd, &sockwr_set))
ProcessWriteEvent(); ProcessWriteEvent();
m_internal->ReleaseData();
#if wxUSE_THREADS #if wxUSE_THREADS
#ifdef Yield #ifdef Yield
#undef Yield #undef Yield
@@ -387,6 +392,20 @@ void wxSocketInternal::EndRequest(SockRequest *req)
delete node; delete node;
} }
void wxSocketInternal::AcquireData()
{
#if wxUSE_THREADS
m_socket_locker.Lock();
#endif
}
void wxSocketInternal::ReleaseData()
{
#if wxUSE_THREADS
m_socket_locker.Unlock();
#endif
}
void wxSocketInternal::AcquireFD() void wxSocketInternal::AcquireFD()
{ {
#if wxUSE_THREADS #if wxUSE_THREADS
@@ -433,21 +452,23 @@ void wxSocketInternal::StopRequester()
m_end_requester.Lock(); m_end_requester.Lock();
if (m_invalid_requester) { if (m_invalid_requester) {
m_end_requester.Unlock(); m_end_requester.Unlock();
delete m_thread_requester; if (m_thread_requester) {
m_thread_requester = NULL; delete m_thread_requester;
m_invalid_requester = FALSE; m_thread_requester = NULL;
}
m_invalid_requester = TRUE;
return; return;
} }
m_end_requester.Unlock(); m_end_requester.Unlock();
wxASSERT(m_thread_requester != NULL); wxASSERT(m_thread_requester != NULL);
m_socket_locker.Lock(); m_request_locker.Lock();
// Send a signal to the requester. // Send a signal to the requester.
m_socket_cond.Signal(); m_socket_cond.Signal();
m_socket_locker.Unlock(); m_request_locker.Unlock();
// Finish the destruction of the requester. // Finish the destruction of the requester.
m_thread_requester->Delete(); m_thread_requester->Delete();
@@ -494,13 +515,10 @@ void wxSocketInternal::StopWaiter()
void wxSocketInternal::QueueRequest(SockRequest *request, bool async) void wxSocketInternal::QueueRequest(SockRequest *request, bool async)
{ {
#if wxUSE_THREADS #if wxUSE_THREADS
/*
if (m_invalid_requester) if (m_invalid_requester)
ResumeRequester(); ResumeRequester();
*/
m_thread_requester = new SocketRequester(m_socket, this);
/* async = FALSE;
if (async) { if (async) {
m_request_locker.Lock(); m_request_locker.Lock();
@@ -522,7 +540,6 @@ void wxSocketInternal::QueueRequest(SockRequest *request, bool async)
} }
} }
} else { } else {
*/
m_request_locker.Lock(); m_request_locker.Lock();
if ((request->type & wxSocketBase::REQ_WAIT) != 0) { if ((request->type & wxSocketBase::REQ_WAIT) != 0) {
@@ -543,9 +560,7 @@ void wxSocketInternal::QueueRequest(SockRequest *request, bool async)
} }
request->done = TRUE; request->done = TRUE;
m_request_locker.Unlock(); m_request_locker.Unlock();
// } }
delete m_thread_requester;
m_thread_requester = NULL;
#endif #endif
} }

View File

@@ -543,7 +543,9 @@ void wxSocketBase::SetNotify(wxRequestNotify flags)
if (m_type != SOCK_SERVER) if (m_type != SOCK_SERVER)
flags &= ~REQ_ACCEPT; flags &= ~REQ_ACCEPT;
m_internal->AcquireData();
m_neededreq = flags; m_neededreq = flags;
m_internal->ReleaseData();
if (m_neededreq == 0) if (m_neededreq == 0)
m_internal->StopWaiter(); m_internal->StopWaiter();
else else
@@ -691,10 +693,10 @@ void wxSocketBase::WantBuffer(char *buffer, size_t nbytes,
buf->timeout = 1000; buf->timeout = 1000;
buf_timed_out = FALSE; buf_timed_out = FALSE;
if (m_flags & SPEED) if ((m_flags & SPEED) != 0)
m_internal->QueueRequest(buf, FALSE); m_internal->QueueRequest(buf, FALSE);
else else
if (m_flags & NOWAIT) if ((m_flags & NOWAIT) != 0)
m_internal->QueueRequest(buf, TRUE); m_internal->QueueRequest(buf, TRUE);
else else
m_internal->QueueRequest(buf, TRUE); m_internal->QueueRequest(buf, TRUE);