summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/samples/debug.c
blob: a86a78d94b8dfc35ead2f1576633381f64d94fe8 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* $Id$ */
/* 
 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

/*
 * PURPOSE:
 *   The purpose of this file is to allow debugging of a sample application
 *   using MSVC IDE.
 */

/* To debug a sample application, include the source file here.
 * E.g.:
 *  #include "playfile.c"
 */
//#include "aectest.c"
#include <pjlib.h>


static void on_accept_complete(pj_ioqueue_key_t *key, 
                           pj_ioqueue_op_key_t *op_key, 
                           pj_sock_t sock, 
                           pj_status_t status)
{
}

static void on_read_complete(pj_ioqueue_key_t *key, 
                         pj_ioqueue_op_key_t *op_key, 
                         pj_ssize_t bytes_read)
{
}


int main()
{
    pj_status_t status;
    pj_caching_pool cp;
    pj_pool_t *pool;
    pj_sock_t sock, new_sock;
    pj_ioqueue_t *ioqueue;
    pj_ioqueue_op_key_t op_key;
    pj_ioqueue_callback cb;
    pj_ioqueue_key_t *key;

    status = pj_init();
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);

    pj_caching_pool_init(&cp, NULL, 0);
    pool = pj_pool_create(&cp.factory, "app", 1000, 1000, NULL);

    status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock);
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);
    
    status = pj_sock_bind_in(sock, 0, 80);
    if (status != PJ_SUCCESS)
	return 1;

    status = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioqueue);
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);

    status = pj_sock_listen(sock, 5);
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);

    pj_bzero(&cb, sizeof(cb));
    cb.on_accept_complete = &on_accept_complete;
    cb.on_read_complete = &on_read_complete;

    status = pj_ioqueue_register_sock(pool, ioqueue, sock, NULL, &cb, &key);
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);

    pj_ioqueue_op_key_init(&op_key, sizeof(op_key));
    status = pj_ioqueue_accept(key, &op_key, &new_sock, NULL, NULL, NULL);
    PJ_ASSERT_RETURN(status==PJ_EPENDING, 1);
}