2003-05-25 03:54:13 +02:00
|
|
|
#ifndef IO_H
|
|
|
|
#define IO_H
|
2003-06-26 20:47:49 +02:00
|
|
|
/*=========================================================================*\
|
|
|
|
* Input/Output abstraction
|
|
|
|
* LuaSocket toolkit
|
|
|
|
*
|
|
|
|
* This module defines the interface that LuaSocket expects from the
|
|
|
|
* transport layer for streamed input/output. The idea is that if any
|
|
|
|
* transport implements this interface, then the buffer.c functions
|
|
|
|
* automatically work on it.
|
|
|
|
*
|
|
|
|
* The module socket.h implements this interface, and thus the module tcp.h
|
|
|
|
* is very simple.
|
|
|
|
*
|
|
|
|
* RCS ID: $Id$
|
|
|
|
\*=========================================================================*/
|
2003-06-09 20:23:40 +02:00
|
|
|
#include <stdio.h>
|
2003-06-26 20:47:49 +02:00
|
|
|
#include <lua.h>
|
2003-06-09 20:23:40 +02:00
|
|
|
|
2004-07-01 05:32:09 +02:00
|
|
|
#include "timeout.h"
|
|
|
|
|
2003-06-09 20:23:40 +02:00
|
|
|
/* IO error codes */
|
|
|
|
enum {
|
2004-07-15 08:11:53 +02:00
|
|
|
IO_DONE = 0, /* operation completed successfully */
|
|
|
|
IO_TIMEOUT = -1, /* operation timed out */
|
|
|
|
IO_CLOSED = -2, /* the connection has been closed */
|
2004-07-16 08:48:48 +02:00
|
|
|
IO_CLIPPED = -3, /* maxium bytes count reached */
|
|
|
|
IO_UNKNOWN = -4
|
2003-06-09 20:23:40 +02:00
|
|
|
};
|
2003-05-25 03:54:13 +02:00
|
|
|
|
2004-07-15 08:11:53 +02:00
|
|
|
/* interface to error message function */
|
|
|
|
typedef const char *(*p_error) (
|
2004-07-16 08:48:48 +02:00
|
|
|
void *ctx, /* context needed by send */
|
2004-07-15 08:11:53 +02:00
|
|
|
int err /* error code */
|
|
|
|
);
|
|
|
|
|
2003-05-25 03:54:13 +02:00
|
|
|
/* interface to send function */
|
|
|
|
typedef int (*p_send) (
|
2004-07-16 08:48:48 +02:00
|
|
|
void *ctx, /* context needed by send */
|
2003-05-25 03:54:13 +02:00
|
|
|
const char *data, /* pointer to buffer with data to send */
|
|
|
|
size_t count, /* number of bytes to send from buffer */
|
|
|
|
size_t *sent, /* number of bytes sent uppon return */
|
2004-07-01 05:32:09 +02:00
|
|
|
p_tm tm /* timeout control */
|
|
|
|
);
|
|
|
|
|
2003-05-25 03:54:13 +02:00
|
|
|
/* interface to recv function */
|
|
|
|
typedef int (*p_recv) (
|
2004-07-16 08:48:48 +02:00
|
|
|
void *ctx, /* context needed by recv */
|
2003-05-25 03:54:13 +02:00
|
|
|
char *data, /* pointer to buffer where data will be writen */
|
|
|
|
size_t count, /* number of bytes to receive into buffer */
|
|
|
|
size_t *got, /* number of bytes received uppon return */
|
2004-07-01 05:32:09 +02:00
|
|
|
p_tm tm /* timeout control */
|
2003-05-25 03:54:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/* IO driver definition */
|
|
|
|
typedef struct t_io_ {
|
|
|
|
void *ctx; /* context needed by send/recv */
|
|
|
|
p_send send; /* send function pointer */
|
|
|
|
p_recv recv; /* receive function pointer */
|
2004-07-15 08:11:53 +02:00
|
|
|
p_error error; /* strerror function */
|
2003-05-25 03:54:13 +02:00
|
|
|
} t_io;
|
|
|
|
typedef t_io *p_io;
|
|
|
|
|
2004-07-15 08:11:53 +02:00
|
|
|
void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx);
|
2004-07-16 08:48:48 +02:00
|
|
|
const char *io_strerror(int err);
|
2003-05-25 03:54:13 +02:00
|
|
|
|
2004-07-26 06:03:55 +02:00
|
|
|
#endif /* IO_H */
|
|
|
|
|