src/io.h

Tue, 05 Jul 2011 18:12:17 -0700

author
Paul Aurich <paul@darkrain42.org>
date
Tue, 05 Jul 2011 18:12:17 -0700
changeset 44
b3a0d23e5b20
parent 0
f7d2d78eb424
permissions
-rw-r--r--

ssl: Add a missing call to setciphers()

0
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 #ifndef IO_H
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 #define IO_H
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 /*=========================================================================*\
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 * LuaSocket 2.0.2
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2004-2007 Diego Nehab
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 *
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 * Input/Output abstraction
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 *
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 * This module defines the interface that LuaSocket expects from the
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 * transport layer for streamed input/output. The idea is that if any
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 * transport implements this interface, then the buffer.c functions
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 * automatically work on it.
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 *
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 * The module socket.h implements this interface, and thus the module tcp.h
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 * is very simple.
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 *
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 * RCS ID: $Id: io.h 6 2006-04-30 20:33:05Z brunoos $
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 \*=========================================================================*/
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 #include <stdio.h>
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 #include <lua.h>
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 #include "timeout.h"
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 /* IO error codes */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 enum {
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 IO_DONE = 0, /* operation completed successfully */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 IO_TIMEOUT = -1, /* operation timed out */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 IO_CLOSED = -2, /* the connection has been closed */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 IO_UNKNOWN = -3, /* Unknown error */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 IO_SSL = -4 /* SSL error */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 };
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 /* interface to error message function */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 typedef const char *(*p_error) (
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 void *ctx, /* context needed by send */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 int err /* error code */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 );
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 /* interface to send function */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 typedef int (*p_send) (
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 void *ctx, /* context needed by send */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 const char *data, /* pointer to buffer with data to send */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 size_t count, /* number of bytes to send from buffer */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 size_t *sent, /* number of bytes sent uppon return */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 p_timeout tm /* timeout control */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 );
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 /* interface to recv function */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 typedef int (*p_recv) (
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 void *ctx, /* context needed by recv */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 char *data, /* pointer to buffer where data will be writen */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 size_t count, /* number of bytes to receive into buffer */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 size_t *got, /* number of bytes received uppon return */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 p_timeout tm /* timeout control */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 );
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 /* IO driver definition */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 typedef struct t_io_ {
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 void *ctx; /* context needed by send/recv */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 p_send send; /* send function pointer */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 p_recv recv; /* receive function pointer */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 p_error error; /* strerror function */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 } t_io;
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 typedef t_io *p_io;
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx);
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 const char *io_strerror(int err);
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 #endif /* IO_H */
f7d2d78eb424 Initial commit (LuaSec 0.4)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70

mercurial