int irc_add_select_descriptors(irc_session_t * session) { if (session->sock < 0 || session->state == LIBIRC_STATE_INIT || session->state == LIBIRC_STATE_DISCONNECTED) { session->lasterror = LIBIRC_ERR_STATE; return 1; } libirc_mutex_lock(&session->mutex_session); switch (session->state) { case LIBIRC_STATE_CONNECTING: // While connection, only out_set descriptor should be set fdwatch_set_fd(session->sock, FDW_WRITE); break; case LIBIRC_STATE_CONNECTED: // Add input descriptor if there is space in input buffer if (session->incoming_offset < (sizeof (session->incoming_buf) - 1) || (session->flags & SESSIONFL_SSL_WRITE_WANTS_READ) != 0) fdwatch_set_fd(session->sock, FDW_READ); // Add output descriptor if there is something in output buffer if (libirc_findcrlf(session->outgoing_buf, session->outgoing_offset) > 0 || (session->flags & SESSIONFL_SSL_READ_WANTS_WRITE) != 0) fdwatch_set_fd(session->sock, FDW_WRITE); break; } libirc_mutex_unlock(&session->mutex_session); libirc_dcc_add_descriptors(session); return 0; }
int irc_add_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set, int * maxfd) { if ( session->sock < 0 || session->state == LIBIRC_STATE_INIT || session->state == LIBIRC_STATE_DISCONNECTED ) { session->lasterror = LIBIRC_ERR_STATE; return 1; } libirc_mutex_lock (&session->mutex_session); switch (session->state) { case LIBIRC_STATE_CONNECTING: // While connection, only out_set descriptor should be set libirc_add_to_set (session->sock, out_set, maxfd); break; case LIBIRC_STATE_CONNECTED: // Add input descriptor if there is space in input buffer if ( session->incoming_offset < (sizeof (session->incoming_buf) - 1) ) libirc_add_to_set (session->sock, in_set, maxfd); // Add output descriptor if there is something in output buffer if ( libirc_findcrlf (session->outgoing_buf, session->outgoing_offset) > 0 ) libirc_add_to_set (session->sock, out_set, maxfd); break; } libirc_mutex_unlock (&session->mutex_session); libirc_dcc_add_descriptors (session, in_set, out_set, maxfd); return 0; }