aboutsummaryrefslogtreecommitdiffstats
path: root/libglouglou/tests/connect.c
blob: b61107f5a8ffd8c42ba289bff056e648d9ebc105 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#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_ONCE);
  event_base_loop(ev_base, EVLOOP_ONCE);

  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);
}