/[cvs]/eggdrop1.9/testcode/ipv6.c
ViewVC logotype

Contents of /eggdrop1.9/testcode/ipv6.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Wed Jun 19 04:51:54 2002 UTC (17 years, 9 months ago) by stdarg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -0 lines
File MIME type: text/x-chdr
FILE REMOVED
* I think the sockbuf api is almost done

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "my_socket.h"
5 #include "sockbuf.h"
6
7 int server_idx;
8
9 int server_err(int idx, int err, void *client_data)
10 {
11 perror("server_err");
12 exit(0);
13 }
14
15 int server_connect(int idx, void *client_data)
16 {
17 printf("Connected to server!\n");
18 linemode_on(idx);
19 return(0);
20 }
21
22 int server_read(int idx, sockbuf_iobuf_t *data, void *client_data)
23 {
24 printf("%s\n", data->data);
25 return(0);
26 }
27
28 int server_eof(int idx, void *client_data)
29 {
30 printf("Server closed connection!\n");
31 exit(0);
32 }
33
34 static sockbuf_event_t server_event = {
35 (Function) 5,
36 (Function) "server",
37 server_read,
38 NULL,
39 server_eof,
40 server_err,
41 server_connect
42 };
43
44 int stdin_read(int idx, sockbuf_iobuf_t *data, void *client_data)
45 {
46 data->data[data->len] = '\n';
47 sockbuf_write(server_idx, data->data, data->len+1);
48 return(0);
49 }
50
51
52 int stdin_eof(int idx, void *client_data)
53 {
54 exit(0);
55 }
56
57 static sockbuf_event_t stdin_event = {
58 (Function) 3,
59 (Function) "stdin",
60 stdin_read,
61 NULL,
62 stdin_eof,
63 };
64
65 main (int argc, char *argv[])
66 {
67 int sock, port, stdin_idx;
68 char *host;
69
70 srand(time(0));
71 if (argc < 2) {
72 host = "::1";
73 port = 12345;
74 }
75 else if (argc == 2) {
76 host = argv[1];
77 port = 12345;
78 }
79 else {
80 host = argv[1];
81 port = atoi(argv[2]);
82 }
83
84 printf("Connecting to %s %d\n", host, port);
85 sock = socket_create(host, port, NULL, 0, SOCKET_CLIENT);
86 if (sock < 0) {
87 perror("socket_create");
88 return(0);
89 }
90 socket_set_nonblock(sock, 1);
91 socket_set_nonblock(0, 1);
92 server_idx = sockbuf_new(sock, SOCKBUF_CLIENT);
93 sockbuf_set_handler(server_idx, server_event, NULL);
94
95 stdin_idx = sockbuf_new(0, 0);
96 sockbuf_set_handler(stdin_idx, stdin_event, NULL);
97 linemode_on(stdin_idx);
98 while (1) {
99 sockbuf_update_all(-1);
100 }
101 return(0);
102 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23