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 
00200 int link_putvfstring(struct link *link, const char *fmt, time_t stoptime, va_list va);
00201 
00209 int link_usleep(struct link *link, int usec, int reading, int writing);
00210 
00211 int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading, int writing);
00212 
00220 int link_sleep(struct link *link, time_t stoptime, int reading, int writing);
00221 
00225 void link_close(struct link *link);
00226 
00227 
00232 void link_detach(struct link *link);
00233 
00245 void link_window_set(int send_window, int recv_window);
00246 
00253 void link_window_get(struct link *link, int *send_window, int *recv_window);
00254 
00266 int link_readline(struct link *link, char *line, size_t length, time_t stoptime);
00267 
00272 int link_fd(struct link *link);
00273 
00274 int link_keepalive(struct link *link, int onoff);
00275 
00276 int link_nonblocking(struct link *link, int onoff);
00277 
00278 
00283 int link_buffer_empty(struct link *link);
00284 
00291 int link_address_local(struct link *link, char *addr, int *port);
00292 
00299 int link_address_remote(struct link *link, char *addr, int *port);
00300 
00301 INT64_T link_stream_to_buffer(struct link *link, char **buffer, time_t stoptime);
00302 
00303 INT64_T link_stream_to_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00304 INT64_T link_stream_to_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00305 
00306 INT64_T link_stream_from_fd(struct link *link, int fd, INT64_T length, time_t stoptime);
00307 INT64_T link_stream_from_file(struct link *link, FILE * file, INT64_T length, time_t stoptime);
00308 
00309 INT64_T link_soak(struct link *link, INT64_T length, time_t stoptime);
00310 
00312 typedef enum {
00313         LINK_TUNE_INTERACTIVE,  
00314         LINK_TUNE_BULK          
00315 } link_tune_t;
00316 
00323 int link_tune(struct link *link, link_tune_t mode);
00324 
00326 #define LINK_READ 1
00327 
00329 #define LINK_WRITE 2
00330 
00332 struct link_info {
00333         struct link *link;  
00334         int events;         
00335         int revents;        
00336 };
00337 
00346 int link_poll(struct link_info *array, int nlinks, int msec);
00347 
00348 #endif

Generated on 30 Jul 2013 for cctools by  doxygen 1.6.1