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             (*error)(struct ct_socket *);
00045         int             (*recv)(struct ct_socket *);
00046         int             (*send)(struct ct_socket *);
00047         int             (*process)(struct ct_socket *, header_t *,
00048                                         ct_buf_t *, ct_buf_t *);
00049         void            (*close)(struct ct_socket *);
00050 
00051         pid_t           client_id;
00052         uid_t           client_uid;
00053 } ct_socket_t;
00054 
00055 #define CT_SOCKET_BUFSIZ 4096
00056 
00057 extern ct_socket_t *    ct_socket_new(unsigned int);
00058 extern void             ct_socket_free(ct_socket_t *);
00059 extern void             ct_socket_reuseaddr(int);
00060 extern int              ct_socket_connect(ct_socket_t *, const char *);
00061 extern int              ct_socket_listen(ct_socket_t *, const char *, int);
00062 extern ct_socket_t *    ct_socket_accept(ct_socket_t *);
00063 extern void             ct_socket_close(ct_socket_t *);
00064 extern int              ct_socket_call(ct_socket_t *, ct_buf_t *, ct_buf_t *);
00065 extern int              ct_socket_flsbuf(ct_socket_t *, int);
00066 extern int              ct_socket_filbuf(ct_socket_t *, long);
00067 extern int              ct_socket_put_packet(ct_socket_t *,
00068                                 header_t *, ct_buf_t *);
00069 extern int              ct_socket_puts(ct_socket_t *, const char *);
00070 extern int              ct_socket_get_packet(ct_socket_t *,
00071                                 header_t *, ct_buf_t *);
00072 extern int              ct_socket_gets(ct_socket_t *, char *, size_t);
00073 extern int              ct_socket_send(ct_socket_t *, header_t *,
00074                                 ct_buf_t *);
00075 extern int              ct_socket_recv(ct_socket_t *, header_t *,
00076                                 ct_buf_t *);
00077 extern int              ct_socket_write(ct_socket_t *, void *, size_t);
00078 extern int              ct_socket_read(ct_socket_t *, void *, size_t);
00079 extern void             ct_socket_link(ct_socket_t *, ct_socket_t *);
00080 extern void             ct_socket_unlink(ct_socket_t *);
00081 extern int              ct_socket_getpeername(ct_socket_t *, char *, size_t);
00082 
00083 #ifdef __cplusplus
00084 }
00085 #endif
00086 
00087 #endif /* OPENCT_SOCKET_H */

libp11, Copyright (C) 2005 Olaf Kirch <okir@lst.de>OpenSC-Project.org Logo