示例#1
0
文件: main.cpp 项目: jojo911/iocp_use
int main(void)
{
	hExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	clients = (int*)malloc(sizeof(int)*MAX_CLIENTS);
	ss = socket_server_create(socket_callback);


	HANDLE h = (HANDLE)_beginthreadex(NULL, 0, test, 0, 0, NULL);

	WaitForSingleObject(h, INFINITE);
	int i;
	for (i=0; i<MAX_CLIENTS; ++i)
	{
		socket_server_close(ss, 100+i, clients[i]);
	}

	socket_server_exit(ss);
	socket_server_wait_for_exit(ss);
	socket_server_release(ss);

	printf("test end\n");
	printf("expected bytes: %d send bytes: %d recv bytes: %d\n", EXPECTED_BYTES, sent_bytes, recv_bytes);
	free(clients);
	system("pause");
	return 0;
}
示例#2
0
static void
test(struct socket_server *ss) {
	pthread_t pid;
	pthread_create(&pid, NULL, _poll, ss);

	int c = socket_server_connect(ss,100,"127.0.0.1",80);
	printf("connecting %d\n",c);
	int l = socket_server_listen(ss,200,"127.0.0.1",8888,32);
	printf("listening %d\n",l);
	socket_server_start(ss,201,l);
	int b = socket_server_bind(ss,300,1);
	printf("binding stdin %d\n",b);
	int i;
	for (i=0;i<100;i++) {
		socket_server_connect(ss, 400+i, "127.0.0.1", 8888);
	}
	sleep(5);
	socket_server_exit(ss);

	pthread_join(pid, NULL); 
}
示例#3
0
int main(void)
{
	clients = (int*)malloc(sizeof(int)*MAX_CLIENTS);
	ss = socket_server_create(socket_callback);


	HANDLE h = (HANDLE)_beginthreadex(NULL, 0, test, 0, 0, NULL);

	WaitForSingleObject(h, INFINITE);
	int i;
	for (i=0; i<MAX_CLIENTS; ++i)
	{
		socket_server_close(ss, 100+i, clients[i]);
	}

	socket_server_exit(ss);
	socket_server_wait_for_exit(ss);
	socket_server_release(ss);

	printf("test end\n");
	free(clients);
	system("pause");
	return 0;
}
示例#4
0
void
skynet_socket_exit() {
	socket_server_exit(SOCKET_SERVER);
}