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 
00075 struct link *link_serve(int port);
00076 
00083 struct link *link_serve_range(int low, int high);
00084 
00091 struct link *link_serve_address(const char *addr, int port);
00092 
00100 struct link *link_serve_addrrange(const char *addr, int low, int high);
00101 
00107 struct link *link_accept(struct link *master, time_t stoptime);
00108 
00118 int link_read(struct link *link, char *data, size_t length, time_t stoptime);
00119 
00129 int link_read_avail(struct link *link, char *data, size_t length, time_t stoptime);
00130 
00138 int link_write(struct link *link, const char *data, size_t length, time_t stoptime);
00139 
00140 /* Write a string of length len to a connection. All data is written until
00141  * finished or an error is encountered.
00142 @param link The link to write.
00143 @param str A pointer to the string.
00144 @param len Length of the string.
00145 @param stoptime The time at which to abort.
00146 @return The number of bytes actually written, or less than zero on error.
00147 */
00148 int link_putlstring(struct link *link, const char *str, size_t len, time_t stoptime);
00149 
00150 /* Write a C string to a connection. All data is written until finished or an
00151    error is encountered. It is defined as a macro.
00152 @param link The link to write.
00153 @param str A pointer to the string.
00154 @param stoptime The time at which to abort.
00155 @return The number of bytes actually written, or less than zero on error.
00156 */
00157 #define link_putstring(l,s,t)  (link_putlstring(l,s,strlen(s),t))
00158 
00159 /* Write a C literal string to a connection. All data is written until finished
00160    or an error is encountered. It is defined as a macro.
00161 @param link The link to write.
00162 @param str A pointer to the string.
00163 @param stoptime The time at which to abort.
00164 @return The number of bytes actually written, or less than zero on error.
00165 */
00166 #define link_putliteral(l,s,t)  (link_putlstring(l,s "",((sizeof(s))-1),t))
00167 
00176 int link_putfstring(struct link *link, const char *fmt, time_t stoptime, ...);
00177 
00186 int link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
00187 
00195 int link_usleep(struct link *link, int usec, int reading, int writing);
00196 
00204 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
00205 
00209 void link_close(struct link *link);
00210 
00222 void link_window_set(int send_window, int recv_window);
00223 
00230 void link_window_get(struct link *link, int *send_window, int *recv_window);
00231 
00243 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
00244 
00249 int link_fd(struct link *link);
00250 
00251 int link_keepalive(struct link *link, int onoff);
00252 
00253 int link_nonblocking(struct link *link, int onoff);
00254 
00255 
00260 int link_buffer_empty(struct link *link);
00261 
00268 int link_address_local(struct link *link, char *addr, int *port);
00269 
00276 int link_address_remote(struct link *link, char *addr, int *port);
00277 
00278 INT64_T link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
00279 
00280 INT64_T link_stream_to_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00281 INT64_T link_stream_to_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00282 
00283 INT64_T link_stream_from_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00284 INT64_T link_stream_from_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00285 
00286 INT64_T link_soak(struct link *link, INT64_T length, time_t stoptime);
00287 
00289 typedef enum {
00290         LINK_TUNE_INTERACTIVE,  
00291         LINK_TUNE_BULK          
00292 } link_tune_t;
00293 
00300 int link_tune(struct link *link, link_tune_t mode);
00301 
00303 #define LINK_READ 1
00304 
00306 #define LINK_WRITE 2
00307 
00309 struct link_info {
00310         struct link *link;  
00311         int events;         
00312         int revents;        
00313 };
00314 
00323 int link_poll(struct link_info *array, int nlinks, int msec);
00324 
00325 #endif

Generated on 11 Feb 2013 for cctools by  doxygen 1.6.1