-bool InspSocket::Poll()
-{
- if (this->Instance->SE->GetRef(this->fd) != this)
- return false;
-
- int incoming = -1;
- bool n = true;
-
- if ((fd < 0) || (fd > MAX_DESCRIPTORS))
- return false;
-
- switch (this->state)
- {
- case I_CONNECTING:
- this->Instance->Log(DEBUG,"State = I_CONNECTING");
- /* Our socket was in write-state, so delete it and re-add it
- * in read-state.
- */
- if (this->fd > -1)
- {
- this->Instance->SE->DelFd(this);
- this->SetState(I_CONNECTED);
- if (!this->Instance->SE->AddFd(this))
- return false;
- }
- return this->OnConnected();
- break;
- case I_LISTENING:
- length = sizeof (client);
- incoming = accept (this->fd, (sockaddr*)&client,&length);
- this->SetQueues(incoming);
-#ifdef IPV6
- this->OnIncomingConnection(incoming,(char*)insp_ntoa(client.sin6_addr));
-#else
- this->OnIncomingConnection(incoming,(char*)insp_ntoa(client.sin_addr));
-#endif
- return true;
- break;
- case I_CONNECTED:
-
- if (this->WaitingForWriteEvent)
- {
- /* Switch back to read events */
- this->Instance->SE->DelFd(this);
- this->WaitingForWriteEvent = false;
- if (!this->Instance->SE->AddFd(this))
- return false;
-
- /* Trigger the write event */
- n = this->OnWriteReady();
- }
- else
- {
- /* Process the read event */
- n = this->OnDataReady();
- }
- /* Flush any pending, but not till after theyre done with the event
- * so there are less write calls involved.
- * Both FlushWriteBuffer AND the return result of OnDataReady must
- * return true for this to be ok.
- */
- if (this->FlushWriteBuffer())
- return false;
- return n;
- break;
- default:
- break;