sdk/modules/lte/altcom/api/socket/altcom_send.c
/****************************************************************************
 * Name: altcom_send
 *
 * Description:
 *   The altcom_send() call may be used only when the socket is in
 *   a connected state (so that the intended recipient is known). The only
 *   difference between altcom_send() and altcom_write() is the presence of
 *   flags. With zero flags parameter, altcom_send() is equivalent to 
 *   altcom_write(). Also, send(sockfd,buf,len,flags) is equivalent to
 *   altcom_sendto(sockfd,buf,len,flags,NULL,0).
 *
 * Parameters:
 *   sockfd   Socket descriptor of socket
 *   buf      Data to send
 *   len      Length of data to send
 *   flags    Send flags
 *
 * Returned Value:
 *   On success, returns the number of characters sent. On error,
 *   -1 is returned, and errno is set appropriately.
 *
 ****************************************************************************/
altcom_send
Description:
The altcom_send() call may be used only when the socket is in
a connected state (so that the intended recipient is known). The only
difference between altcom_send() and altcom_write() is the presence of
flags. With zero flags parameter, altcom_send() is equivalent to
altcom_write().

sockfd   Socket descriptor of socket
buf      Data to send
len      Length of data to send
flags    Send flags

Returned Value:
On success, returns the number of characters sent. On error,
-1 is returned, and errno is set appropriately.
altcom_send Description : The altcom_send () call may be used only when the socket is in a connected state ( so that the intended recipient is known ) . The only difference between altcom_send () and altcom_write () is the presence of flags . With zero flags parameter altcom_send () is equivalent to altcom_write () . sockfd Socket descriptor of socket buf Data to send len Length of data to send flags Send flags Returned Value : On success returns the number of characters sent . On error - 1 is returned and errno is set appropriately .
int altcom_send(int sockfd, const void *buf, size_t len, int flags)
{
  int32_t                     ret;
  int32_t                     result;
  struct altcom_fd_set_s      writeset;
  FAR struct altcom_socket_s  *fsock;
  struct send_req_s           req;
  FAR struct altcom_timeval   *sendtimeo;
  if (!altcom_isinit())
    {
      DBGIF_LOG_ERROR("Not intialized\n");
      altcom_seterrno(ALTCOM_ENETDOWN);
      return -1;
    }
  fsock = altcom_sockfd_socket(sockfd);
  if (!fsock)
    {
      altcom_seterrno(ALTCOM_EINVAL);
      return -1;
    }
  if (len > APICMD_SEND_SENDDATA_LENGTH)
    {
      DBGIF_LOG2_WARNING("Truncate send length:%d -> %d.\n", len, APICMD_SEND_SENDDATA_LENGTH);
      len = APICMD_SEND_SENDDATA_LENGTH;
    }
  if (!buf)
    {
      DBGIF_LOG_ERROR("buf is NULL\n");
      altcom_seterrno(ALTCOM_EINVAL);
      return -1;
    }
  req.sockfd = sockfd;
  req.buf    = buf;
  req.len    = len;
  req.flags  = flags;
  if (fsock->flags & ALTCOM_O_NONBLOCK)
    {
      ALTCOM_FD_ZERO(&writeset);
      ALTCOM_FD_SET(sockfd, &writeset);
      ret = altcom_select_nonblock((sockfd + 1), NULL, &writeset, NULL);
      if (ret > 0)
        {
          if (!ALTCOM_FD_ISSET(sockfd, &writeset))
            {
              altcom_seterrno(ALTCOM_EFAULT);
              DBGIF_LOG1_ERROR("select failed: %d\n", altcom_errno());
              return -1;
            }
          result = send_request(fsock, &req);
          if (result == SEND_REQ_FAILURE)
            {
              return -1;
            }
        }
      else
        {
          if (ret == 0)
            {
              altcom_seterrno(ALTCOM_EAGAIN);
            }
          else
            {
              DBGIF_LOG1_ERROR("select failed: %d\n", altcom_errno());
            }
          return -1;
        }
    }
  else
    {
      ALTCOM_FD_ZERO(&writeset);
      ALTCOM_FD_SET(sockfd, &writeset);
      sendtimeo = &fsock->sendtimeo;
      if ((fsock->sendtimeo.tv_sec == 0) && (fsock->sendtimeo.tv_usec == 0))
      {
        sendtimeo = NULL;
      }
      ret = altcom_select_block((sockfd + 1), NULL, &writeset, NULL, sendtimeo);
      if (ret <= 0)
        {
          if (ret == 0)
            {
              altcom_seterrno(ALTCOM_EFAULT);
            }
          if (altcom_errno() == ALTCOM_ETIMEDOUT)
            {
              altcom_seterrno(ALTCOM_EAGAIN);
            }
          DBGIF_LOG1_ERROR("select failed: %d\n", altcom_errno());
          return -1;
        }
      if (!ALTCOM_FD_ISSET(sockfd, &writeset))
        {
          altcom_seterrno(ALTCOM_EFAULT);
          DBGIF_LOG1_ERROR("select failed: %d\n", altcom_errno());
          return -1;
        }
      result = send_request(fsock, &req);
      if (result == SEND_REQ_FAILURE)
       {
         return -1;
       }
    }
  return result;
}
int altcom_send ( int sockfd , const void * buf , size_t len , int flags ) { int32_t ret ; int32_t result ; struct altcom_fd_set_s writeset ; FAR struct altcom_socket_s * fsock ; struct send_req_s req ; FAR struct altcom_timeval * sendtimeo ; if ( ! altcom_isinit ( ) ) { DBGIF_LOG_ERROR ( " \n " ) ; altcom_seterrno ( ALTCOM_ENETDOWN ) ; return -1 ; } fsock = altcom_sockfd_socket ( sockfd ) ; if ( ! fsock ) { altcom_seterrno ( ALTCOM_EINVAL ) ; return -1 ; } if ( len > APICMD_SEND_SENDDATA_LENGTH ) { DBGIF_LOG2_WARNING ( " \n " , len , APICMD_SEND_SENDDATA_LENGTH ) ; len = APICMD_SEND_SENDDATA_LENGTH ; } if ( ! buf ) { DBGIF_LOG_ERROR ( " \n " ) ; altcom_seterrno ( ALTCOM_EINVAL ) ; return -1 ; } req . sockfd = sockfd ; req . buf = buf ; req . len = len ; req . flags = flags ; if ( fsock -> flags & ALTCOM_O_NONBLOCK ) { ALTCOM_FD_ZERO ( & writeset ) ; ALTCOM_FD_SET ( sockfd , & writeset ) ; ret = altcom_select_nonblock ( ( sockfd + 1 ) , NULL , & writeset , NULL ) ; if ( ret > 0 ) { if ( ! ALTCOM_FD_ISSET ( sockfd , & writeset ) ) { altcom_seterrno ( ALTCOM_EFAULT ) ; DBGIF_LOG1_ERROR ( " \n " , altcom_errno ( ) ) ; return -1 ; } result = send_request ( fsock , & req ) ; if ( result == SEND_REQ_FAILURE ) { return -1 ; } } else { if ( ret == 0 ) { altcom_seterrno ( ALTCOM_EAGAIN ) ; } else { DBGIF_LOG1_ERROR ( " \n " , altcom_errno ( ) ) ; } return -1 ; } } else { ALTCOM_FD_ZERO ( & writeset ) ; ALTCOM_FD_SET ( sockfd , & writeset ) ; sendtimeo = & fsock -> sendtimeo ; if ( ( fsock -> sendtimeo . tv_sec == 0 ) && ( fsock -> sendtimeo . tv_usec == 0 ) ) { sendtimeo = NULL ; } ret = altcom_select_block ( ( sockfd + 1 ) , NULL , & writeset , NULL , sendtimeo ) ; if ( ret <= 0 ) { if ( ret == 0 ) { altcom_seterrno ( ALTCOM_EFAULT ) ; } if ( altcom_errno ( ) == ALTCOM_ETIMEDOUT ) { altcom_seterrno ( ALTCOM_EAGAIN ) ; } DBGIF_LOG1_ERROR ( " \n " , altcom_errno ( ) ) ; return -1 ; } if ( ! ALTCOM_FD_ISSET ( sockfd , & writeset ) ) { altcom_seterrno ( ALTCOM_EFAULT ) ; DBGIF_LOG1_ERROR ( " \n " , altcom_errno ( ) ) ; return -1 ; } result = send_request ( fsock , & req ) ; if ( result == SEND_REQ_FAILURE ) { return -1 ; } } return result ; }
Name: altcom_send
 Description:
   The altcom_send() call may be used only when the socket is in
   a connected state (so that the intended recipient is known).
Name : altcom_send Description : The altcom_send () call may be used only when the socket is in a connected state ( so that the intended recipient is known ) .
/* Check length of data to send */ /* Truncate the length to the maximum transfer size */ /* Check send buffer is available */ /* Send send request */ /* Wait until send buffer is available */