00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef LIBPLUMBING_ENDPOINT_H
00019 #define LIBPLUMBING_ENDPOINT_H
00020
00021 #include <boost/shared_ptr.hpp>
00022
00023 #include <cstdio>
00024 #include <string>
00025 #include <libplumbing/format_printf.h>
00026
00027 namespace plumbing {
00028
00029 class time_value;
00030
00043 class endpoint
00044 {
00045 public:
00052 typedef boost::shared_ptr<endpoint> pointer;
00053
00057 virtual ~endpoint();
00058
00059 protected:
00068 endpoint(int fd);
00069
00084 endpoint(int fd, const void *sock_addr, int sock_addr_len);
00085
00086 public:
00101 virtual int get_read_file_descriptor();
00102
00122 virtual int get_write_file_descriptor();
00123
00128 virtual void process_read() = 0;
00129
00134 virtual void process_write() = 0;
00135
00149 virtual void process_timeout();
00150
00156 bool is_ready_to_die() const;
00157
00167 virtual time_value get_maximum_sleep() const;
00168
00169 protected:
00181 int fd;
00182
00191 void fatal_error(const char *fmt, ...)
00192 FORMAT_PRINTF(2, 3);
00202 static int parse_port_number(const std::string &text);
00203
00220 static int parse_port_number_or_die(const std::string &text,
00221 bool empty_is_ok = false);
00222
00234 void fatal_error_v(const char *fmt, va_list ap)
00235 FORMAT_PRINTF(2, 0);
00243 void warning(const char *fmt, ...)
00244 FORMAT_PRINTF(2, 3);
00255 void warning_v(const char *fmt, va_list ap)
00256 FORMAT_PRINTF(2, 0);
00266 void set_peer_name(const char *name);
00267
00277 void set_peer_name(const std::string &name);
00278
00284 const char *get_peer_name() const { return peer_name.c_str(); }
00285
00286 protected:
00292 virtual void close();
00293
00299 void kill_me_now();
00300
00301 private:
00307 std::string peer_name;
00308
00314 bool ready_to_die;
00315
00321 void set_peer_name();
00322
00334 void set_peer_name(const void *sock_addr, int sock_addr_len);
00335
00339 endpoint();
00340
00344 endpoint(const endpoint &);
00345
00349 endpoint &operator=(const endpoint &);
00350 };
00351
00352 }
00353
00354 #endif // LIBPLUMBING_ENDPOINT_H