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

usocket.h

Go to the documentation of this file.
00001 #ifndef DV_NET_USOCKET_H 00002 #define DV_NET_USOCKET_H 00003 00004 // $Id: usocket.h,v 1.7 2002/10/18 18:15:37 dvermeir Exp $ 00005 #include <iostream> 00006 #include <dvutil/ref.h> 00007 #include <dvnet/usockstreambuf.h> 00008 00009 /*! \file 00010 This file defines the Dv::Net::Usocket class. 00011 */ 00012 namespace Dv { 00013 namespace Net { 00014 class userversocket; 00015 //! Unix socket iostream specialization. 00016 class usocket: public std::iostream { 00017 public: 00018 00019 //! Open client socket on filename connected to servername. 00020 /*! If filename has size 0, a temporary file will be created in /tmp 00021 */ 00022 explicit usocket(const std::string& servername, time_t millisecs=0, 00023 const std::string& filename=""); 00024 00025 /** Construct a connection accepted by a server. 00026 \param srv server doing the accept 00027 \param delay (in millisecs) that we are prepared to wait, 0 means forever. 00028 \param bufsize of resulting socket 00029 00030 Upon failure or timeout, the usocket is still created, but its 00031 failbit will be set, which can be checked as follows. 00032 00033 \code 00034 usocket connection(server,10,bufsize); 00035 if (connection) { 00036 } 00037 \endcode 00038 00039 The delay (for I/O operations) of the new socket, is inherited from 00040 the userversocket. 00041 */ 00042 usocket(userversocket& srv, time_t delay, size_t bufsize); 00043 00044 //! Construct a connection accepted by a server. 00045 static Util::ref<usocket> accept(userversocket& srv, time_t delay, size_t bufsize); 00046 00047 //! Destructor. 00048 ~usocket(); 00049 00050 //! Return filename of server. 00051 const std::string& servername() const { return servername_; } 00052 00053 //! Return associated usockstreambuf object. 00054 usockstreambuf* rdbuf(void) const { 00055 return static_cast<usockstreambuf*>(std::istream::rdbuf()); 00056 } 00057 00058 //! Return last system error. 00059 int error() const { return rdbuf()->error(); } 00060 //! Return last system error string. 00061 std::string strerror() const { return rdbuf()->strerror(); } 00062 00063 private: 00064 00065 usocket(const usocket&); 00066 usocket& operator=(const usocket&); 00067 00068 std::string servername_; 00069 bool temp_; 00070 }; 00071 }} 00072 #endif

dvnet-0.9.11 [27 December, 2004]