socket.h

00001 /*
00002  * Socket type definitions
00003  *
00004  * Copyright (C) 2003, Olaf Kirch <okir@suse.de>
00005  */
00006 
00007 #ifndef OPENCT_SOCKET_H
00008 #define OPENCT_SOCKET_H
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 #include <sys/types.h>
00015 #include <openct/types.h>
00016 #include <openct/buffer.h>
00017 
00018 /* forward decl */
00019 struct pollfd;
00020 
00021 typedef struct header {
00022         uint32_t        xid;
00023         uint32_t        dest;
00024         int16_t         error;
00025         uint16_t        count;
00026 } header_t;
00027 
00028 typedef struct ct_socket {
00029         struct ct_socket *next, *prev;
00030 
00031         int             fd;
00032         int             eof;
00033         ct_buf_t        rbuf, sbuf;
00034 
00035         unsigned int    use_large_tags : 1,
00036                         use_network_byte_order : 1,
00037                         listener : 1;
00038 
00039         /* events to poll for */
00040         int             events;
00041 
00042         void *          user_data;
00043         int             (*poll)(struct ct_socket *, struct pollfd *);
00044         int             (*recv)(struct ct_socket *);
00045         int             (*send)(struct ct_socket *);
00046         int             (*process)(struct ct_socket *, header_t *,
00047                                         ct_buf_t *, ct_buf_t *);
00048         void            (*close)(struct ct_socket *);
00049 
00050         pid_t           client_id;
00051         uid_t           client_uid;
00052 } ct_socket_t;
00053 
00054 #define CT_SOCKET_BUFSIZ 4096
00055 
00056 extern ct_socket_t *    ct_socket_new(unsigned int);
00057 extern void             ct_socket_free(ct_socket_t *);
00058 extern void             ct_socket_reuseaddr(int);
00059 extern int              ct_socket_connect(ct_socket_t *, const char *);
00060 extern int              ct_socket_listen(ct_socket_t *, const char *, int);
00061 extern ct_socket_t *    ct_socket_accept(ct_socket_t *);
00062 extern void             ct_socket_close(ct_socket_t *);
00063 extern int              ct_socket_call(ct_socket_t *, ct_buf_t *, ct_buf_t *);
00064 extern int              ct_socket_flsbuf(ct_socket_t *, int);
00065 extern int              ct_socket_filbuf(ct_socket_t *, long);
00066 extern int              ct_socket_put_packet(ct_socket_t *,
00067                                 header_t *, ct_buf_t *);
00068 extern int              ct_socket_puts(ct_socket_t *, const char *);
00069 extern int              ct_socket_get_packet(ct_socket_t *,
00070                                 header_t *, ct_buf_t *);
00071 extern int              ct_socket_gets(ct_socket_t *, char *, size_t);
00072 extern int              ct_socket_send(ct_socket_t *, header_t *,
00073                                 ct_buf_t *);
00074 extern int              ct_socket_recv(ct_socket_t *, header_t *,
00075                                 ct_buf_t *);
00076 extern int              ct_socket_write(ct_socket_t *, void *, size_t);
00077 extern int              ct_socket_read(ct_socket_t *, void *, size_t);
00078 extern void             ct_socket_link(ct_socket_t *, ct_socket_t *);
00079 extern void             ct_socket_unlink(ct_socket_t *);
00080 extern int              ct_socket_getpeername(ct_socket_t *, char *, size_t);
00081 
00082 #ifdef __cplusplus
00083 }
00084 #endif
00085 
00086 #endif /* OPENCT_SOCKET_H */

Generated on Thu Aug 30 20:21:19 2007 for OpenCT by  doxygen 1.5.1