1 #ifndef __NET_SENDBUFFER_H 2 #define __NET_SENDBUFFER_H 3 4 #define DEFAULT_BUFFER_SIZE 8192 5 #define MAX_BUFFER_SIZE 1048576 6 7 struct _NET_SENDBUF_REC { 8 GIOChannel *handle; 9 LINEBUF_REC *readbuffer; /* receive buffer */ 10 11 int send_tag; 12 int bufsize; 13 int bufpos; 14 char *buffer; /* Buffer is NULL until it's actually needed. */ 15 int def_bufsize; 16 unsigned int dead:1; 17 }; 18 19 /* Create new buffer - if `bufsize' is zero or less, DEFAULT_BUFFER_SIZE 20 is used */ 21 NET_SENDBUF_REC *net_sendbuffer_create(GIOChannel *handle, int bufsize); 22 /* Destroy the buffer. `close' specifies if socket handle should be closed. */ 23 void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close); 24 25 /* Send data, if all of it couldn't be sent immediately, it will be resent 26 automatically after a while. Returns -1 if some unrecoverable error 27 occurred. */ 28 int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size); 29 30 int net_sendbuffer_receive_line(NET_SENDBUF_REC *rec, char **str, int read_socket); 31 32 /* Flush the buffer, blocks until finished. */ 33 void net_sendbuffer_flush(NET_SENDBUF_REC *rec); 34 35 /* Returns the socket handle */ 36 GIOChannel *net_sendbuffer_handle(NET_SENDBUF_REC *rec); 37 38 #endif 39