00001 #ifndef DV_NET_USERVERSOCKET_H 00002 #define DV_NET_USERVERSOCKET_H 00003 00004 // $Id: userversocket.h,v 1.8 2008/03/14 21:47:49 dvermeir Exp $ 00005 #include <stdexcept> 00006 #include <dvutil/shared_ptr.h> 00007 #include <dvnet/usocket.h> 00008 00009 /** @file 00010 * This file defines the Dv::Net::usocket (client) class. 00011 */ 00012 namespace Dv { 00013 namespace Net { 00014 /** Class representing a server listening on a unix socket. */ 00015 class userversocket: public DebugSlave { 00016 public: 00017 /** Constructor. 00018 * @param filename associated with newly created unix socket 00019 * @param delay in millisecs that will be associated with connections to the server 00020 * @param nconnections queue size of unix socket 00021 * @param min_debug_level if a debug_master is connected, logging info 00022 * will only be written if the master's level is at least @a min_debug_level 00023 * @param debug_master from where debug info will be taken 00024 * @see Dv::DebugSlave 00025 */ 00026 explicit userversocket(const std::string& filename, time_t delay=0, int nconnections=5, 00027 unsigned int min_debug_level = 0, Debugable* debug_master = 0); 00028 /** Destructor. */ 00029 ~userversocket(); 00030 /** Accept a client connection. 00031 * \param delay in millisecs before accept() will time out 00032 * \param bufsz that will be associated with client socket 00033 * 00034 * The success can be tested by testing the status of the returned usocket. 00035 * @code 00036 * Dv::Util::ref<Dv::Net::usocket> client(server.accept()); 00037 * if (*client) { 00038 * // all is well 00039 * } 00040 * @endcode 00041 */ 00042 shared_ptr<usocket> accept(time_t delay=0, size_t bufsz=1024) { 00043 return usocket::accept(*this,delay,bufsz); 00044 } 00045 /** @return the filename of underlying unix socket. */ 00046 std::string filename() const { return fn_; } 00047 /** @return max delay in millisecs that accept will wait before failing. */ 00048 time_t delay() const { return delay_; } 00049 /** @return file descriptor of unix socket. */ 00050 int fd() const { return fd_; } 00051 /** @return whether server is ok. */ 00052 bool status() const { return errno_ == 0; } 00053 /** @return whether server is ok. */ 00054 operator bool() const { return status(); } 00055 /** @return error code, 0 == ok. */ 00056 int error() const { return errno_; } 00057 /** @return status string. */ 00058 std::string strerror() const; 00059 private: 00060 /** Forbidden. */ 00061 userversocket(const userversocket&); 00062 /** Forbidden. */ 00063 userversocket& operator=(const userversocket&); 00064 std::string fn_; 00065 int fd_; 00066 int errno_; 00067 time_t delay_; 00068 }; 00069 } 00070 } 00071 #endif
dvnet-0.9.24 | [ 5 December, 2009] |