Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

userversocket.h

Go to the documentation of this file.
00001 #ifndef DV_NET_USERVERSOCKET_H 00002 #define DV_NET_USERVERSOCKET_H 00003 00004 // $Id: userversocket.h,v 1.4 2002/10/18 18:15:37 dvermeir Exp $ 00005 #include <stdexcept> 00006 #include <dvutil/ref.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 00015 //! Class representing a server listening on a unix socket. 00016 class userversocket { 00017 public: 00018 //! Constructor. 00019 /*! \param filename associated with newly created unix socket 00020 \param delay in millisecs that will be associated with connections to the server 00021 \param nconnections queue size of unix socket 00022 */ 00023 explicit userversocket(const std::string& filename, time_t delay=0, int nconnections=5); 00024 //! Destructor. 00025 ~userversocket(); 00026 00027 //! Accept a client connection. 00028 /*! \param delay in millisecs before accept() will time out 00029 \param bufsz that will be associated with client socket 00030 00031 The success can be tested by testing the status of 00032 the returned usocket. 00033 \code 00034 ref<usocket> client(server.accept()); 00035 00036 if (*client) { 00037 // all is well 00038 } 00039 \endcode 00040 */ 00041 Util::ref<usocket> accept(time_t delay=0,size_t bufsz=1024) { 00042 return usocket::accept(*this,delay,bufsz); 00043 } 00044 //! Filename of underlying unix socket. 00045 std::string filename() const { return fn_; } 00046 //! Max delay in millisecs that accept will wait before failing. 00047 time_t delay() const { return delay_; } 00048 //! File descriptor of unix socket. 00049 int fd() const { return fd_; } 00050 //! Return whether server is ok. 00051 bool status() const { return errno_ == 0; } 00052 //! Return whether server is ok. 00053 operator bool() const { return status(); } 00054 //! Return error code, 0 == ok. 00055 int error() const { return errno_; } 00056 //! Return status string. 00057 std::string strerror() const; 00058 private: 00059 userversocket(const userversocket&); 00060 userversocket& operator=(const userversocket&); 00061 00062 std::string fn_; 00063 int fd_; 00064 int errno_; 00065 time_t delay_; 00066 }; 00067 00068 }} 00069 00070 #endif

dvnet-0.9.11 [27 December, 2004]