OpenCT  0.6.20
socket.h
1 /*
2  * Socket type definitions
3  *
4  * Copyright (C) 2003, Olaf Kirch <okir@suse.de>
5  */
6 
7 #ifndef OPENCT_SOCKET_H
8 #define OPENCT_SOCKET_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <sys/types.h>
15 #include <openct/types.h>
16 #include <openct/buffer.h>
17 
18 /* forward decl */
19 struct pollfd;
20 
21 typedef struct header {
22  uint32_t xid;
23  uint32_t dest;
24  int16_t error;
25  uint16_t count;
26 } header_t;
27 
28 typedef struct ct_socket {
29  struct ct_socket *next, *prev;
30 
31  int fd;
32  int eof;
33  ct_buf_t rbuf, sbuf;
34 
35  unsigned int use_large_tags : 1,
36  use_network_byte_order : 1,
37  listener : 1;
38 
39  /* events to poll for */
40  int events;
41 
42  void * user_data;
43  int (*poll)(struct ct_socket *, struct pollfd *);
44  int (*error)(struct ct_socket *);
45  int (*recv)(struct ct_socket *);
46  int (*send)(struct ct_socket *);
47  int (*process)(struct ct_socket *, header_t *,
48  ct_buf_t *, ct_buf_t *);
49  void (*close)(struct ct_socket *);
50 
51  pid_t client_id;
52  uid_t client_uid;
53 } ct_socket_t;
54 
55 #define CT_SOCKET_BUFSIZ 4096
56 
57 extern ct_socket_t * ct_socket_new(unsigned int);
58 extern void ct_socket_free(ct_socket_t *);
59 extern void ct_socket_reuseaddr(int);
60 extern int ct_socket_connect(ct_socket_t *, const char *);
61 extern int ct_socket_listen(ct_socket_t *, const char *, int);
62 extern ct_socket_t * ct_socket_accept(ct_socket_t *);
63 extern void ct_socket_close(ct_socket_t *);
64 extern int ct_socket_call(ct_socket_t *, ct_buf_t *, ct_buf_t *);
65 extern int ct_socket_flsbuf(ct_socket_t *, int);
66 extern int ct_socket_filbuf(ct_socket_t *, long);
67 extern int ct_socket_put_packet(ct_socket_t *,
68  header_t *, ct_buf_t *);
69 extern int ct_socket_puts(ct_socket_t *, const char *);
70 extern int ct_socket_get_packet(ct_socket_t *,
71  header_t *, ct_buf_t *);
72 extern int ct_socket_gets(ct_socket_t *, char *, size_t);
73 extern int ct_socket_send(ct_socket_t *, header_t *,
74  ct_buf_t *);
75 extern int ct_socket_recv(ct_socket_t *, header_t *,
76  ct_buf_t *);
77 extern int ct_socket_write(ct_socket_t *, void *, size_t);
78 extern int ct_socket_read(ct_socket_t *, void *, size_t);
79 extern void ct_socket_link(ct_socket_t *, ct_socket_t *);
80 extern void ct_socket_unlink(ct_socket_t *);
81 extern int ct_socket_getpeername(ct_socket_t *, char *, size_t);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif /* OPENCT_SOCKET_H */
Definition: buffer.h:16
Definition: socket.h:21

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