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 
00084 struct link * link_serve_address( const char *addr, int port );
00085 
00091 struct link * link_accept( struct link *master, time_t stoptime );
00092 
00102 int  link_read( struct link *link, char *data, size_t length, time_t stoptime );
00103 
00113 int  link_read_avail( struct link *link, char *data, size_t length, time_t stoptime );
00114 
00122 int  link_write( struct link *link, const char *data, size_t length, time_t stoptime );
00123 
00124 /* Write a string of length len to a connection. All data is written until
00125  * finished or an error is encountered.
00126 @param link The link to write.
00127 @param str A pointer to the string.
00128 @param len Length of the string.
00129 @param stoptime The time at which to abort.
00130 @return The number of bytes actually written, or less than zero on error.
00131 */
00132 int  link_putlstring( struct link *link, const char *str, size_t len, time_t stoptime);
00133 
00134 /* Write a C string to a connection. All data is written until finished or an
00135    error is encountered. It is defined as a macro.
00136 @param link The link to write.
00137 @param str A pointer to the string.
00138 @param stoptime The time at which to abort.
00139 @return The number of bytes actually written, or less than zero on error.
00140 */
00141 #define link_putstring(l,s,t)  (link_putlstring(l,s,strlen(s),t))
00142 
00143 /* Write a C literal string to a connection. All data is written until finished
00144    or an error is encountered. It is defined as a macro.
00145 @param link The link to write.
00146 @param str A pointer to the string.
00147 @param stoptime The time at which to abort.
00148 @return The number of bytes actually written, or less than zero on error.
00149 */
00150 #define link_putliteral(l,s,t)  (link_putlstring(l,s "",((sizeof(s))-1),t))
00151 
00160 int  link_putfstring( struct link *link, const char *fmt, time_t stoptime, ... );
00161 
00170 int  link_putvfstring( struct link *link, const char *fmt, time_t stoptime, va_list va );
00171 
00179 int  link_usleep( struct link *link, int usec, int reading, int writing );
00180 
00184 void link_close( struct link *link );
00185 
00197 void link_window_set( int send_window, int recv_window );
00198 
00205 void link_window_get( struct link *link, int *send_window, int *recv_window );
00206 
00218 int  link_readline( struct link *link, char *line, size_t length, time_t stoptime );
00219 
00224 int  link_fd( struct link *link );
00225 
00226 int  link_nonblocking( struct link *link, int onoff );
00227 
00234 int  link_address_local( struct link *link, char *addr, int *port );
00235 
00242 int  link_address_remote( struct link *link, char *addr, int *port );
00243 
00244 INT64_T link_stream_to_buffer( struct link *link, char **buffer, time_t stoptime );
00245 
00246 INT64_T link_stream_to_fd( struct link *link, int fd, INT64_T length, time_t stoptime );
00247 INT64_T link_stream_to_file( struct link *link, FILE *file, INT64_T length, time_t stoptime );
00248 
00249 INT64_T link_stream_from_fd( struct link *link, int fd, INT64_T length, time_t stoptime );
00250 INT64_T link_stream_from_file( struct link *link, FILE *file, INT64_T length, time_t stoptime );
00251 
00252 INT64_T link_soak( struct link *link, INT64_T length, time_t stoptime );
00253 
00255 typedef enum {
00256         LINK_TUNE_INTERACTIVE,  
00257         LINK_TUNE_BULK          
00258 } link_tune_t;
00259 
00266 int  link_tune( struct link *link, link_tune_t mode );
00267 
00269 #define LINK_READ 1
00270 
00272 #define LINK_WRITE 2
00273 
00275 struct link_info {
00276         struct link *link;  
00277         int events;         
00278         int revents;        
00279 };
00280 
00289 int  link_poll( struct link_info *array, int nlinks, int msec );
00290 
00291 #endif
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303 
00304 

Generated on Wed Apr 13 09:36:06 2011 for cctools by  doxygen 1.4.7