aboutsummaryrefslogblamecommitdiffstats
path: root/libglouglou/tests/connect.c
blob: 2a203c8edf659b83b9bc87ae2d35c4b7437f3573 (plain) (tree)
1
2
3
4
5
6
7
8
9



                           

                       

   
                                                           
 


                                   




                                      

                           

 


          





















                                                                   
 
#include <event.h>

#include "../libglouglou.h"

int srv_connect_ok = 0;
int cli_connect_ok = 0;

int
srv_handle_conn(struct gg_server *srv, struct gg_user *usr)
{
	if (usr->id == 0)
		srv_connect_ok = 1;
	return 0;
}

int
cli_handle_conn(struct gg_client *cli)
{
	cli_connect_ok = 1;
	return 0;
}

int
main(void)
{
	struct event_base *ev_base;

	ev_base = event_base_new();
	if (!gg_server_start(ev_base, "127.0.0.1", 12345,
				srv_handle_conn,NULL, NULL)) {
		printf("error: gg_server_start returned NULL\n");
		return 1;
	}
	if (!gg_client_connect(ev_base, "127.0.0.1", 12345,
				cli_handle_conn, NULL, NULL)) {
		printf("error: gg_client_connect returned NULL\n");
		return 1;
	}
	event_base_loop(ev_base, EVLOOP_NONBLOCK);
	event_base_loop(ev_base, EVLOOP_NONBLOCK);

	if (srv_connect_ok == 0)
		printf("error: srv_connect_ok == 0\n");
	if (cli_connect_ok == 0)
		printf("error: cli_connect_ok == 0\n");

	return (!srv_connect_ok || !cli_connect_ok);
}