src/cloud.c
void cloud_sessionSend(CLOUD_SESSION_T *s)
{
   ssize_t retVal;
   struct  timeval tv;
   fd_set  writefds;
   size_t  start_index;
   int32_t remain_bytes_to_send;

   if ((CLOUD_SESSION_IDLE != s->status) &&
       (CLOUD_SESSION_FAILED != s->status) &&
       (CLOUD_SESSION_CONNECT_SUCCESS != s->status) &&
       (CLOUD_SESSION_SEND_PENDING != s->status))
   {
      /* 
       * Do not perform a send operation if the socket is not IDLE, FAILED,
       * connect success, or send in progress.
       */
      return;
   }
   if (CLOUD_SESSION_SEND_PENDING != s->status)
   {
      cloud_setSessionStatus(s, CLOUD_SESSION_SEND_PENDING);
      s->totalBytesSent = 0;
   }
   FD_ZERO(&writefds);
   FD_SET(s->handle, &writefds);
   tv.tv_sec = SEND_TIMEOUT_MS / 1000;
   tv.tv_usec = 0;
   retVal = select(s->handle+1, NULL, &writefds, NULL, &tv);
   if (retVal >= 0)
   {
      if (FD_ISSET(s->handle, &writefds))
      {
         start_index = s->totalBytesSent;
         remain_bytes_to_send = s->totalBytesToSend - s->totalBytesSent;
         if (remain_bytes_to_send < 0)
         {
            return;
         }
         retVal = send(s->handle, &(s->sendBuf[start_index]), remain_bytes_to_send, 0);
         if (CLOUD_SOCKET_ERROR == retVal)
         {
            if ((EINPROGRESS != errno) && (EWOULDBLOCK != errno))
            {
               utils_sysLog(LOG_ERR, "%s>> send failed errno: %s\n", s->name, strerror(errno));
               cloud_handleSocketError(s, errno);
            }
         }
         else
         {
            s->totalBytesSent += retVal;
            if (s->totalBytesSent == s->totalBytesToSend)
            {
               cloud_setSessionStatus(s, CLOUD_SESSION_SEND_SUCCESS);
               s->totalBytesSent = 0;
            }
         }
      }
      else
      {
         utils_sysLog(LOG_ERR, "%s>> send FD_ISSET errno: %s\n", s->name, strerror(errno));
      }
   }
   else
   {
      utils_sysLog(LOG_ERR, "%s>> send select errno: %s\n", s->name, strerror(errno));
   }
}
//!
//! Wrapper function to send data on a socket for non-blocking socket operations.
//! Check whether the socket is ready to send data using a select() call then
//! send the data through the socket.
//!
//! This function returns CALS_FAIL if the socket is not ready for send or if an
//! error occurs during the send operation.  If no error occured, the number of
//! bytes sent is returned.
//!
//! NOTE:  It is possible that not all bytes have been sent out through the
//!        socket! The caller is responsible to make successive calls to this
//!        function to send the remaining data out.
//!
//! @param[in] *s pointer to a Cloud session structure object.
//!

Wrapper function to send data on a socket for non-blocking socket operations.
Check whether the socket is ready to send data using a select() call then
send the data through the socket.

This function returns CALS_FAIL if the socket is not ready for send or if an
error occurs during the send operation.  If no error occured, the number of
bytes sent is returned.

It is possible that not all bytes have been sent out through the
socket. The caller is responsible to make successive calls to this
function to send the remaining data out.
Wrapper function to send data on a socket for non - blocking socket operations . Check whether the socket is ready to send data using a select () call then send the data through the socket . This function returns CALS_FAIL if the socket is not ready for send or if an error occurs during the send operation . If no error occured the number of bytes sent is returned . It is possible that not all bytes have been sent out through the socket . The caller is responsible to make successive calls to this function to send the remaining data out .
void cloud_sessionSend(CLOUD_SESSION_T *s)
{
   ssize_t retVal;
   struct  timeval tv;
   fd_set  writefds;
   size_t  start_index;
   int32_t remain_bytes_to_send;
   if ((CLOUD_SESSION_IDLE != s->status) &&
       (CLOUD_SESSION_FAILED != s->status) &&
       (CLOUD_SESSION_CONNECT_SUCCESS != s->status) &&
       (CLOUD_SESSION_SEND_PENDING != s->status))
   {
      return;
   }
   if (CLOUD_SESSION_SEND_PENDING != s->status)
   {
      cloud_setSessionStatus(s, CLOUD_SESSION_SEND_PENDING);
      s->totalBytesSent = 0;
   }
   FD_ZERO(&writefds);
   FD_SET(s->handle, &writefds);
   tv.tv_sec = SEND_TIMEOUT_MS / 1000;
   tv.tv_usec = 0;
   retVal = select(s->handle+1, NULL, &writefds, NULL, &tv);
   if (retVal >= 0)
   {
      if (FD_ISSET(s->handle, &writefds))
      {
         start_index = s->totalBytesSent;
         remain_bytes_to_send = s->totalBytesToSend - s->totalBytesSent;
         if (remain_bytes_to_send < 0)
         {
            return;
         }
         retVal = send(s->handle, &(s->sendBuf[start_index]), remain_bytes_to_send, 0);
         if (CLOUD_SOCKET_ERROR == retVal)
         {
            if ((EINPROGRESS != errno) && (EWOULDBLOCK != errno))
            {
               utils_sysLog(LOG_ERR, "%s>> send failed errno: %s\n", s->name, strerror(errno));
               cloud_handleSocketError(s, errno);
            }
         }
         else
         {
            s->totalBytesSent += retVal;
            if (s->totalBytesSent == s->totalBytesToSend)
            {
               cloud_setSessionStatus(s, CLOUD_SESSION_SEND_SUCCESS);
               s->totalBytesSent = 0;
            }
         }
      }
      else
      {
         utils_sysLog(LOG_ERR, "%s>> send FD_ISSET errno: %s\n", s->name, strerror(errno));
      }
   }
   else
   {
      utils_sysLog(LOG_ERR, "%s>> send select errno: %s\n", s->name, strerror(errno));
   }
}
void cloud_sessionSend ( CLOUD_SESSION_T * s ) { ssize_t retVal ; struct timeval tv ; fd_set writefds ; size_t start_index ; int32_t remain_bytes_to_send ; if ( ( CLOUD_SESSION_IDLE != s -> status ) && ( CLOUD_SESSION_FAILED != s -> status ) && ( CLOUD_SESSION_CONNECT_SUCCESS != s -> status ) && ( CLOUD_SESSION_SEND_PENDING != s -> status ) ) { return ; } if ( CLOUD_SESSION_SEND_PENDING != s -> status ) { cloud_setSessionStatus ( s , CLOUD_SESSION_SEND_PENDING ) ; s -> totalBytesSent = 0 ; } FD_ZERO ( & writefds ) ; FD_SET ( s -> handle , & writefds ) ; tv . tv_sec = SEND_TIMEOUT_MS / 1000 ; tv . tv_usec = 0 ; retVal = select ( s -> handle + 1 , NULL , & writefds , NULL , & tv ) ; if ( retVal >= 0 ) { if ( FD_ISSET ( s -> handle , & writefds ) ) { start_index = s -> totalBytesSent ; remain_bytes_to_send = s -> totalBytesToSend - s -> totalBytesSent ; if ( remain_bytes_to_send < 0 ) { return ; } retVal = send ( s -> handle , & ( s -> sendBuf [ start_index ] ) , remain_bytes_to_send , 0 ) ; if ( CLOUD_SOCKET_ERROR == retVal ) { if ( ( EINPROGRESS != errno ) && ( EWOULDBLOCK != errno ) ) { utils_sysLog ( LOG_ERR , " \n " , s -> name , strerror ( errno ) ) ; cloud_handleSocketError ( s , errno ) ; } } else { s -> totalBytesSent += retVal ; if ( s -> totalBytesSent == s -> totalBytesToSend ) { cloud_setSessionStatus ( s , CLOUD_SESSION_SEND_SUCCESS ) ; s -> totalBytesSent = 0 ; } } } else { utils_sysLog ( LOG_ERR , " \n " , s -> name , strerror ( errno ) ) ; } } else { utils_sysLog ( LOG_ERR , " \n " , s -> name , strerror ( errno ) ) ; } }
Wrapper function to send data on a socket for non-blocking socket operations.
Wrapper function to send data on a socket for non - blocking socket operations .
/* 
       * Do not perform a send operation if the socket is not IDLE, FAILED,
       * connect success, or send in progress.
       */