summaryrefslogtreecommitdiff
path: root/tests/connection2-test.c
blob: c2bc3708ccd40ddba2f370783bf603ae9b9ab66d (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
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */

/*  Lac - Library for asynchronous communication
 *  Copyright (C) 2002  Søren Sandmann (sandmann@daimi.au.dk)
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the 
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA  02111-1307, USA.
 */
#include <lac.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/tcp.h>
#include <string.h>

int
main (int argc, char *argv[])
{
    LacAddress *addr =
        lac_address_new_from_name_wait ("www.toyota.co.jp", NULL, NULL);
    int fd;
    guchar blah[60000];
    GTimer *timer;
    int len;
    
    g_assert (addr);

    fd = lac_socket_tcp (NULL);

    g_assert (fd > 0);

    g_assert (lac_connect (fd, addr, 80, NULL));

#define line1 "GET / HTTP/1.1\r\n"
#define line2 "host: www.toyota.co.jp\r\n\r\n"

    timer = g_timer_new ();
    
    lac_send (fd, line1, strlen (line1), NULL);
    lac_send (fd, line2, strlen (line2), NULL);

    lac_set_nagle (fd, FALSE, NULL);
    lac_set_nagle (fd, TRUE, NULL);

#if 0
    lac_send (fd, line1 line2, strlen (line1) + strlen (line2), NULL);
#endif

    while ((len = lac_recv (fd, blah, sizeof (blah), NULL)) > 0)
    {
        int i;
        for (i = 0; i < len; ++i)
            g_print ("%c", blah[i]);
    }

    g_print ("elapsed: %f\n", g_timer_elapsed (timer, NULL));

    return 0;
}