示例#1
0
文件: lsocket.c 项目: nan1888/lask
/*
** fd, err = socket.socket(af, socktype, protocol=nil)
*/
static int lsocket_socket(lua_State *L) 
{
	int fd, err;
	err = socket_socket(luaL_checkint(L, 1), luaL_checkint(L, 2), luaL_optint(L, 3, 0), &fd);
	if (err == 0) {
		lua_pushinteger(L, fd);
	} else {
		lua_pushinteger(L, -1);
	}
	lua_pushinteger(L, err);
	return 2;
}
示例#2
0
/**
 * Create and bind a socket for the Ethernet device
 *
 * @param   eth_dev_num      - Ethernet device number
 * @param   socket_index     - Socket index (return value)
 * @param   udp_port         - UDP port number
 *
 * @return  int              - Status of the command:
 *                                 XST_SUCCESS - Command completed successfully
 *                                 XST_FAILURE - There was an error in the command
 *
 *****************************************************************************/
int transport_config_socket(u32 eth_dev_num, int * socket_index, u32 udp_port) {

    int status;
    int tmp_socket  = *socket_index;

    // Release socket if it is already bound
    if (tmp_socket != SOCKET_INVALID_SOCKET) {
        socket_close(tmp_socket);
    }

    // Create a new socket
    tmp_socket = socket_socket(AF_INET, SOCK_DGRAM, 0);

    if (tmp_socket == SOCKET_INVALID_SOCKET) {
        wlan_exp_printf(WLAN_EXP_PRINT_ERROR, print_type_transport, "Could not create socket\n");

        * socket_index = SOCKET_INVALID_SOCKET;

        return XST_FAILURE;
    }

    // Bind the socket
    status = socket_bind_eth(tmp_socket, eth_dev_num, udp_port);

    if (status == WARP_IP_UDP_FAILURE) {
        wlan_exp_printf(WLAN_EXP_PRINT_ERROR, print_type_transport, "Unable to bind socket on port: %d\n", udp_port);

        socket_close(tmp_socket);

        * socket_index = SOCKET_INVALID_SOCKET;

        return XST_FAILURE;
    }

    * socket_index = tmp_socket;

    return XST_SUCCESS;
}