示例#1
0
/* This is an initialization function where the user program opens connections */
static int
mbasc_slave_init (int argc, char **argv)
{
	MHANDLE conp;
	UARTPRM uart;
	USERFUN funs;

	memset(&uart, 0, sizeof(UARTPRM));
	if (argc < 2)
	{
		printf("usage: <progname> <port>\n");
		return -1;
	}
	uart.port = atoi(argv[1]);
	uart.baudrate = 9600;
	uart.parity = MSP_PARITY_NONE;	/* 0~4: none, odd, even, mark, space */
	uart.data_bits = 8;	/* 5,6,7,8 */
	uart.stop_bits = 1;	/* 1,2,3 (1.5 bits) */
	uart.iface_mode = MSP_RS232_MODE;	/* 0~3: RS232, RS485_2WIRE, RS422, RS485_4WIRE */
	uart.flow_control = MSP_FLOWCTRL_HW;	/* 0~2: none, software, hardware  */

	/* callback functions */
	memset(&funs, 0 , sizeof(USERFUN));
	funs.open = mbasc_slave_open;
	funs.dispatch = mbasc_slave_dispatch;
	funs.close = mbasc_slave_close;

	/* make a client connection */
	if ((conp=connection_open (CONNECTION_TYPE_UARTPORT, &uart, &funs, NULL)) == NULL)
		return -1;

	return 0;
}
示例#2
0
int
driver_connect (driver_t *driver, device_desc_t *desc, connection_t *connection)
{
	int error;
	
	if (unlikely(driver == NULL))
		LOG_ERROR_AND_RETURN(-1, "null driver_t");
	
	if (unlikely(driver->connect == NULL))
		LOG_ERROR_AND_RETURN(-101, "[%s] null connect function pointer", driver->desc.name);
	
	if (unlikely(0 != (error = (*driver->connect)(driver, desc))))
		LOG_ERROR_AND_RETURN(-102, "[%s] failed to driver->connection, %d", driver->desc.name, error);
	
	connection->context1 = driver;
	connection->context2 = desc;
	connection->send = __driver_send;
	connection->recv = __driver_recv;
	connection->available = __driver_available;
	connection->endian = driver->endian;
	
	if (unlikely(0 != (error = connection_open(connection))))
		LOG_ERROR_AND_RETURN(-103, "[%s] failed to connection_open(0, %d", driver->desc.name, error);
	
	return 0;
}
示例#3
0
/* This is an initialization function where the user program opens connections */
static int
udp_server_init (int argc, char **argv)
{
	MHANDLE con;
	UDPXPRM srvr;
	USERFUN funs;

	memset(&srvr, 0, sizeof(UDPXPRM));
	if (argc > 1)
		srvr.listen_port = atoi(argv[1]);
	else
		srvr.listen_port = SERVER_LISTEN_PORT;

	/* callback functions */
	memset(&funs, 0 , sizeof(USERFUN));
	funs.open = udp_server_accept_client;
	funs.dispatch = udp_server_dispatch_client;
	funs.close = udp_server_close_client;

	/* make a client connection */
	if ((con=connection_open (CONNECTION_TYPE_UDPSERVER, &srvr, &funs, NULL)) == NULL)
		return -1;
	else
		return 0;
}
示例#4
0
int
main() {
	struct connection_pool * p = connection_newpool(16);

	int handle = connection_open(p, "127.0.0.1:8888");

	test(p,handle);

	connection_deletepool(p);
	
	return 0;
};
示例#5
0
int proto_connect(struct addrinfo *ai, char *hostname, test_t *test) {
	connection_t *c;

	c = connection_open(ai, hostname);
	if(c == NULL) {
		test->error = errno;
		return -1;
	}

	connection_set_callbacks(c, proto_start, proto_step, proto_finish, test);
	return 0;
}
示例#6
0
int session_begin(SESSION_HANDLE session)
{
	int result;

	if (session == NULL)
	{
		result = __LINE__;
	}
	else
	{
		SESSION_INSTANCE* session_instance = (SESSION_INSTANCE*)session;

		if (connection_start_endpoint(session_instance->endpoint, on_frame_received, on_connection_state_changed, session_instance) != 0)
		{
			result = __LINE__;
		}
		else
		{
			if (!session_instance->is_underlying_connection_open)
			{
				if (connection_open(session_instance->connection) != 0)
				{
					session_instance->is_underlying_connection_open = 0;
					result = __LINE__;
				}
				else
				{
					session_instance->is_underlying_connection_open = 1;
					result = 0;
				}
			}
			else
			{
				result = 0;
			}
		}
	}

	return result;
}
示例#7
0
/* This is an initialization function where the user program opens connections */
static int
mbtcp_client_init (int argc, char **argv)
{
	MHANDLE con;
	CLNTPRM param;
	USERFUN funs;

	if (argc < 3)
	{
		printf("usage: <progname> <hostname> <listen port>\n");
		return -1;
	}
	/* setting the parameters of a server */
	memset(&param, 0 , sizeof(CLNTPRM));
	param.host = argv[1];
	param.listen_port = atoi(argv[2]);

	/* callback functions */
	memset(&funs, 0 , sizeof(USERFUN));
	funs.open = mbtcp_client_open;
	funs.dispatch = mbtcp_client_dispatch;
	funs.close = mbtcp_client_release;

	/* make a client connection */
	if ((con=connection_open (CONNECTION_TYPE_TCPCLIENT, &param, &funs, NULL)) == NULL)
		return -1;
	else
	{
		MBTCPHDR mb;

		memset(&mb, 0 , sizeof(MBTCPHDR));
		/* send 1st packet */
		send_request(con, &mb);
		return 0;
	}
}