Example #1
0
void check_client_fd(aClient *cptr)
{
   if (DoingAuth(cptr))
   {
      unsigned int fdflags = get_fd_flags(cptr->authfd);

      if(!(fdflags & FDF_WANTREAD))
         set_fd_flags(cptr->authfd, FDF_WANTREAD);

      if((cptr->flags & FLAGS_WRAUTH) && !(fdflags & FDF_WANTWRITE))
         set_fd_flags(cptr->authfd, FDF_WANTWRITE);
      else if(!(cptr->flags & FLAGS_WRAUTH) && (fdflags & FDF_WANTWRITE))
         unset_fd_flags(cptr->authfd, FDF_WANTWRITE);

      return;
   }

   if (DoingDNS(cptr))
      return;

   set_fd_flags(cptr->fd, FDF_WANTREAD);
}
Example #2
0
/*
 * deliver_it 
 *
 * Attempt to send a sequence of bytes to the connection. 
 * Returns 
 *  < 0     Some fatal error occurred, (but not EWOULDBLOCK). 
 *    his return is a request to close the socket and clean up the link.
 *  >= 0    No real error occurred, returns the number of bytes actually
 *    transferred. EWOULDBLOCK and other similar conditions should be mapped
 *    to zero return.
 *    Upper level routine will have to decide what to do with
 *    those unwritten bytes... 
 * *NOTE*  alarm calls have been preserved, so this should work equally 
 *  well whether blocking or non-blocking mode is used...
 */
int
deliver_it (aClient * client_p, char *str, int len)
{
  int retval;
  aClient *acpt = client_p->acpt;
#ifdef	DEBUGMODE
  writecalls++;
#endif
#ifdef USE_SSL
  if (IsSSL (client_p) && client_p->ssl)
    retval = safe_SSL_write (client_p, str, len);
  else
#endif
    retval = send (client_p->fd, str, len, 0);

  /*
   * Convert WOULDBLOCK to a return of "0 bytes moved". This 
   * should occur only if socket was non-blocking. Note, that all is
   * Ok, if the 'write' just returns '0' instead of an error and
   * errno=EWOULDBLOCK. 
   */
  if (retval < 0 &&
#ifdef _WIN32
      (WSAGetLastError () == WSAEWOULDBLOCK ||
       WSAGetLastError () == WSAENOBUFS)
#else
      (errno == EWOULDBLOCK || errno == EAGAIN || errno == ENOBUFS)
#endif
    )
  {
    retval = 0;
    client_p->flags |= FLAGS_BLOCKED;
    set_fd_flags (client_p->fd, FDF_WANTWRITE);
    return (retval);            /* Just get out now... */
  }
  else if (retval > 0)
  {
    if (client_p->flags & FLAGS_BLOCKED)
    {
      client_p->flags &= ~FLAGS_BLOCKED;
      unset_fd_flags (client_p->fd, FDF_WANTWRITE);
    }
  }

#ifdef DEBUGMODE
  if (retval < 0)
  {
    writeb[0]++;
    Debug ((DEBUG_ERROR, "write error (%s) to %s",
            strerror (errno), client_p->name));
  }
  else if (retval == 0)
    writeb[1]++;
  else if (retval < 16)
    writeb[2]++;
  else if (retval < 32)
    writeb[3]++;
  else if (retval < 64)
    writeb[4]++;
  else if (retval < 128)
    writeb[5]++;
  else if (retval < 256)
    writeb[6]++;
  else if (retval < 512)
    writeb[7]++;
  else if (retval < 1024)
    writeb[8]++;
  else
    writeb[9]++;
#endif
  if (retval > 0)
  {
    client_p->sendB += retval;
    me.sendB += retval;
    if (client_p->sendB > 1023)
    {
      client_p->sendK += (client_p->sendB >> 10);
      client_p->sendB &= 0x03ff;        /* 2^10 = 1024, 3ff = 1023 */
    }