link.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
00003 Copyright (C) 2005- The University of Notre Dame
00004 This software is distributed under the GNU General Public License.
00005 See the file COPYING for details.
00006 */
00007 
00008 #ifndef LINK_H
00009 #define LINK_H
00010 
00044 #include "int_sizes.h"
00045 
00046 #include <time.h>
00047 #include <limits.h>
00048 #include <stdio.h>
00049 #include <stdarg.h>
00050 #include <sys/types.h>
00051 
00053 #define LINK_ADDRESS_MAX 48
00054 
00056 #define LINK_PORT_ANY 0
00057 
00059 #define LINK_FOREVER ((time_t)INT_MAX)
00060 
00067 struct link *link_connect(const char *addr, int port, time_t stoptime);
00068 
00073 struct link *link_attach_to_file(FILE *file);
00074 
00079 struct link *link_attach_to_fd(int fd);
00080 
00081 
00088 struct link *link_serve(int port);
00089 
00096 struct link *link_serve_range(int low, int high);
00097 
00104 struct link *link_serve_address(const char *addr, int port);
00105 
00113 struct link *link_serve_addrrange(const char *addr, int low, int high);
00114 
00120 struct link *link_accept(struct link *master, time_t stoptime);
00121 
00131 int link_read(struct link *link, char *data, size_t length, time_t stoptime);
00132 
00142 int link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
00143 
00151 int link_write(struct link *link, const char *data, size_t length, time_t stoptime);
00152 
00153 /* Write a string of length len to a connection. All data is written until
00154  * finished or an error is encountered.
00155 @param link The link to write.
00156 @param str A pointer to the string.
00157 @param len Length of the string.
00158 @param stoptime The time at which to abort.
00159 @return The number of bytes actually written, or less than zero on error.
00160 */
00161 int link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
00162 
00163 /* Write a C string to a connection. All data is written until finished or an
00164    error is encountered. It is defined as a macro.
00165 @param link The link to write.
00166 @param str A pointer to the string.
00167 @param stoptime The time at which to abort.
00168 @return The number of bytes actually written, or less than zero on error.
00169 */
00170 #define link_putstring(l,s,t)  (link_putlstring(l,s,strlen(s),t))
00171 
00172 /* Write a C literal string to a connection. All data is written until finished
00173    or an error is encountered. It is defined as a macro.
00174 @param link The link to write.
00175 @param str A pointer to the string.
00176 @param stoptime The time at which to abort.
00177 @return The number of bytes actually written, or less than zero on error.
00178 */
00179 #define link_putliteral(l,s,t)  (link_putlstring(l,s "",((sizeof(s))-1),t))
00180 
00189 int link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...);
00190 
00199 int link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
00200 
00208 int link_usleep(struct link *link, int usec, int reading, int writing);
00209 
00217 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
00218 
00222 void link_close(struct link *link);
00223 
00224 
00229 void link_detach(struct link *link);
00230 
00242 void link_window_set(int send_window, int recv_window);
00243 
00250 void link_window_get(struct link *link, int *send_window, int *recv_window);
00251 
00263 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
00264 
00269 int link_fd(struct link *link);
00270 
00271 int link_keepalive(struct link *link, int onoff);
00272 
00273 int link_nonblocking(struct link *link, int onoff);
00274 
00275 
00280 int link_buffer_empty(struct link *link);
00281 
00288 int link_address_local(struct link *link, char *addr, int *port);
00289 
00296 int link_address_remote(struct link *link, char *addr, int *port);
00297 
00298 INT64_T link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
00299 
00300 INT64_T link_stream_to_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00301 INT64_T link_stream_to_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00302 
00303 INT64_T link_stream_from_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00304 INT64_T link_stream_from_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00305 
00306 INT64_T link_soak(struct link *link, INT64_T length, time_t stoptime);
00307 
00309 typedef enum {
00310         LINK_TUNE_INTERACTIVE,  
00311         LINK_TUNE_BULK          
00312 } link_tune_t;
00313 
00320 int link_tune(struct link *link, link_tune_t mode);
00321 
00323 #define LINK_READ 1
00324 
00326 #define LINK_WRITE 2
00327 
00329 struct link_info {
00330         struct link *link;  
00331         int events;         
00332         int revents;        
00333 };
00334 
00343 int link_poll(struct link_info *array, int nlinks, int msec);
00344 
00345 #endif

Generated on 12 Jun 2013 for cctools by  doxygen 1.4.7