Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_conn.c File Reference
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "gwlib/gwlib.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file test_conn.c.

References conn_destroy(), conn_open_tcp(), debug(), get_and_set_debugs(), gwlib_init(), gwlib_shutdown(), gwthread_sleep(), host, octstr_create, octstr_destroy(), octstr_get_cstr, panic, and port.

71 {
72  Connection *conn;
73  Octstr *host = NULL;
74  int port, i;
75 
76  gwlib_init();
77 
78  get_and_set_debugs(argc, argv, NULL);
79 
80  if (argc < 3)
81  panic(0, "Syntax: %s <host> <port>\n", argv[0]);
82 
83  host = octstr_create(argv[1]);
84  port = atoi(argv[2]);
85  i = 50;
86 
87  debug("",0,"Connecting to host '%s', port %d, looping %i times.",
88  octstr_get_cstr(host), port, i);
89 
90  for (i = 0; i <= 50; i++) {
91  conn = conn_open_tcp(host, port, NULL);
92  if (conn == NULL) {
93  panic(0, "Couldn't connect.");
94  }
95  debug("",0,"%d: connected.", i);
96  gwthread_sleep(0.2);
97  debug("",0,"%d: closing.", i);
98  conn_destroy(conn);
99  }
100 
101  octstr_destroy(host);
102  gwlib_shutdown();
103  return 0;
104 }
Connection * conn_open_tcp(Octstr *host, int port, Octstr *our_host)
Definition: conn.c:488
static Octstr * host
Definition: fakesmsc.c:121
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static int port
Definition: fakesmsc.c:120
void conn_destroy(Connection *conn)
Definition: conn.c:619
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void gwthread_sleep(double seconds)
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
#define panic
Definition: log.h:87
void gwlib_shutdown(void)
Definition: gwlib.c:94
void gwlib_init(void)
Definition: gwlib.c:78
int get_and_set_debugs(int argc, char **argv, int(*find_own)(int index, int argc, char **argv))
Definition: utils.c:626
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.