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 <signal.h>
00051 #include <sys/types.h>
00052 
00054 #define LINK_ADDRESS_MAX 48
00055 
00057 #define LINK_PORT_ANY 0
00058 
00060 #define LINK_FOREVER ((time_t)INT_MAX)
00061 
00068 struct link *link_connect(const char *addr, int port, time_t stoptime);
00069 
00074 struct link *link_attach_to_file(FILE *file);
00075 
00080 struct link *link_attach_to_fd(int fd);
00081 
00082 
00089 struct link *link_serve(int port);
00090 
00097 struct link *link_serve_range(int low, int high);
00098 
00105 struct link *link_serve_address(const char *addr, int port);
00106 
00114 struct link *link_serve_addrrange(const char *addr, int low, int high);
00115 
00121 struct link *link_accept(struct link *master, time_t stoptime);
00122 
00132 int link_read(struct link *link, char *data, size_t length, time_t stoptime);
00133 
00143 int link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
00144 
00152 int link_write(struct link *link, const char *data, size_t length, time_t stoptime);
00153 
00154 /* Write a string of length len to a connection. All data is written until
00155  * finished or an error is encountered.
00156 @param link The link to write.
00157 @param str A pointer to the string.
00158 @param len Length of the string.
00159 @param stoptime The time at which to abort.
00160 @return The number of bytes actually written, or less than zero on error.
00161 */
00162 int link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
00163 
00164 /* Write a C string to a connection. All data is written until finished or an
00165    error is encountered. It is defined as a macro.
00166 @param link The link to write.
00167 @param str A pointer to the string.
00168 @param stoptime The time at which to abort.
00169 @return The number of bytes actually written, or less than zero on error.
00170 */
00171 #define link_putstring(l,s,t)  (link_putlstring(l,s,strlen(s),t))
00172 
00173 /* Write a C literal string to a connection. All data is written until finished
00174    or an error is encountered. It is defined as a macro.
00175 @param link The link to write.
00176 @param str A pointer to the string.
00177 @param stoptime The time at which to abort.
00178 @return The number of bytes actually written, or less than zero on error.
00179 */
00180 #define link_putliteral(l,s,t)  (link_putlstring(l,s "",((sizeof(s))-1),t))
00181 
00190 int link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...)
00191   __attribute__ (( format(printf,2,4) )) ;
00192 
00201 int link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
00202 
00210 int link_usleep(struct link *link, int usec, int reading, int writing);
00211 
00212 int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
00213 
00221 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
00222 
00226 void link_close(struct link *link);
00227 
00228 
00233 void link_detach(struct link *link);
00234 
00246 void link_window_set(int send_window, int recv_window);
00247 
00254 void link_window_get(struct link *link, int *send_window, int *recv_window);
00255 
00267 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
00268 
00273 int link_fd(struct link *link);
00274 
00275 int link_keepalive(struct link *link, int onoff);
00276 
00277 int link_nonblocking(struct link *link, int onoff);
00278 
00279 
00284 int link_buffer_empty(struct link *link);
00285 
00292 int link_address_local(struct link *link, char *addr, int *port);
00293 
00300 int link_address_remote(struct link *link, char *addr, int *port);
00301 
00302 INT64_T link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
00303 
00304 INT64_T link_stream_to_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00305 INT64_T link_stream_to_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00306 
00307 INT64_T link_stream_from_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00308 INT64_T link_stream_from_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00309 
00310 INT64_T link_soak(struct link *link, INT64_T length, time_t stoptime);
00311 
00313 typedef enum {
00314         LINK_TUNE_INTERACTIVE,  
00315         LINK_TUNE_BULK          
00316 } link_tune_t;
00317 
00324 int link_tune(struct link *link, link_tune_t mode);
00325 
00327 #define LINK_READ 1
00328 
00330 #define LINK_WRITE 2
00331 
00333 struct link_info {
00334         struct link *link;  
00335         int events;         
00336         int revents;        
00337 };
00338 
00347 int link_poll(struct link_info *array, int nlinks, int msec);
00348 
00349 #endif

Generated on 11 Dec 2014 for cctools by  doxygen 1.4.7