Beispiel #1
0
INT send( INT sockID, const CHAR *msg, INT msgLength, INT flags )
{
    switch ( sockets[sockID].type )
    {
        case BSD_SOCKET_TCP:
        {
            NX_PACKET* packet;
            INT progress = 0;
            while ( progress != msgLength )
            {
                nx_packet_allocate( &wiced_packet_pools[0], &packet, NX_TCP_PACKET, NX_WAIT_FOREVER );
                INT data_length = MIN( msgLength, sockets[sockID].socket.tcp.nx_tcp_socket_mss );
                nx_packet_data_append( packet, (VOID*) msg, data_length, &wiced_packet_pools[0], NX_WAIT_FOREVER );
                if ( nx_tcp_socket_send(&sockets[sockID].socket.tcp, packet, NX_WAIT_FOREVER) != NX_SUCCESS )
                {
                    nx_packet_release( packet );
                    return BSD_ERROR;
                }
                else
                {
                    progress += data_length;
                    msg += data_length;
                }
            }
            return progress;
            break;
        }
        case BSD_SOCKET_UDP:
        {
            NX_PACKET* packet;
            nx_packet_allocate( &wiced_packet_pools[0], &packet, NX_UDP_PACKET, NX_WAIT_FOREVER );
            nx_packet_data_append( packet, (VOID*) msg, msgLength, &wiced_packet_pools[0], NX_WAIT_FOREVER );
            if ( nx_udp_socket_send(&sockets[sockID].socket.udp, packet, htonl(SOCK4_ADDRESS(&sockets[sockID].last_received_peer)), hton16(SOCK4_PORT(&sockets[sockID].last_received_peer))) != NX_SUCCESS )
            {
                nx_packet_release( packet );
            }
            else
            {
                return msgLength;
            }
            break;
        }
    }

    return BSD_ERROR;
}
Beispiel #2
0
INT sendto( INT sockID, CHAR *msg, INT msgLength, INT flags, struct sockaddr *destAddr, INT destAddrLen )
{
    switch ( sockets[sockID].type )
    {
        case BSD_SOCKET_TCP:
        {
            NX_PACKET* packet;
            nx_packet_allocate( &wiced_packet_pools[0], &packet, NX_TCP_PACKET, NX_WAIT_FOREVER );
            INT data_length = MIN( msgLength, sockets[sockID].socket.tcp.nx_tcp_socket_mss );
            nx_packet_data_append( packet, (VOID*) msg, data_length, &wiced_packet_pools[0], NX_WAIT_FOREVER );
            if ( nx_tcp_socket_send(&sockets[sockID].socket.tcp, packet, NX_WAIT_FOREVER) != NX_SUCCESS )
            {
                nx_packet_release( packet );
            }
            else
            {
                return data_length;
            }
            break;
        }
        case BSD_SOCKET_UDP:
        {
            NX_PACKET* packet;

            /* Note that it's important to specify the packet as NX_IPv4_UDP_PACKET otherwise NetX Duo allocates another 20 bytes for IPv6 header and iperf won't work properly */
            nx_packet_allocate( &wiced_packet_pools[0], &packet, NX_UDP_PACKET, NX_WAIT_FOREVER );
            nx_packet_data_append( packet, msg, msgLength, &wiced_packet_pools[0], NX_WAIT_FOREVER );
            if ( nx_udp_socket_send(&sockets[sockID].socket.udp, packet, htonl(SOCK4_ADDRESS(destAddr)), hton16(SOCK4_PORT(destAddr))) != NX_SUCCESS )
            {
                nx_packet_release( packet );
            }
            else
            {
                return msgLength;
            }
            break;
        }
    }

    return BSD_ERROR;
}
Beispiel #3
0
int s7g2_write(Network* n, unsigned char* buffer, int len, int timeout_ms)
{
  UINT status;
  NX_PACKET       *packet_ptr;
  status =  nx_packet_allocate(n->my_packet_pool, &packet_ptr, NX_TCP_PACKET, timeout_ms);
  if(status) return -1;
  status = nx_packet_data_append(packet_ptr, buffer, len, n->my_packet_pool, timeout_ms);
  if(status) return -1;
  status =  nx_tcp_socket_send(&n->my_socket, packet_ptr, timeout_ms);
  if(status) return -1;
  nx_packet_release(packet_ptr);
  return len;
}
Beispiel #4
0
/* The NetX send callback
 *  return : bytes sent, or error
 */
int NetX_Send(CYASSL* ssl, char *buf, int sz, void *ctx)
{
    NetX_Ctx*       nxCtx = (NetX_Ctx*)ctx;
    NX_PACKET*      packet;
    NX_PACKET_POOL* pool;   /* shorthand */
    UINT            status;

    if (nxCtx == NULL || nxCtx->nxSocket == NULL) {
        CYASSL_MSG("NetX Send NULL parameters");
        return CYASSL_CBIO_ERR_GENERAL;
    }

    pool = nxCtx->nxSocket->nx_tcp_socket_ip_ptr->nx_ip_default_packet_pool;
    status = nx_packet_allocate(pool, &packet, NX_TCP_PACKET,
                                nxCtx->nxWait);
    if (status != NX_SUCCESS) {
        CYASSL_MSG("NetX Send packet alloc error");
        return CYASSL_CBIO_ERR_GENERAL;
    }

    status = nx_packet_data_append(packet, buf, sz, pool, nxCtx->nxWait);
    if (status != NX_SUCCESS) {
        nx_packet_release(packet);
        CYASSL_MSG("NetX Send data append error");
        return CYASSL_CBIO_ERR_GENERAL;
    }

    status = nx_tcp_socket_send(nxCtx->nxSocket, packet, nxCtx->nxWait);
    if (status != NX_SUCCESS) {
        nx_packet_release(packet);
        CYASSL_MSG("NetX Send socket send error");
        return CYASSL_CBIO_ERR_GENERAL;
    }

    return sz;
}