1 // Sun, 18 Jun 2000 2 // Y.Takagi 3 4 #ifndef __SocketStream_H 5 #define __SocketStream_H 6 7 #include <iostream> 8 9 class Socket; 10 11 class socketstreambuf : public streambuf { 12 public: 13 explicit socketstreambuf(Socket *sock, streamsize n); 14 ~socketstreambuf(); 15 16 protected: 17 virtual int underflow(); 18 virtual int overflow(int); 19 virtual int sync(); 20 21 private: 22 Socket *__sock; 23 streamsize __alsize; 24 char *__pu; 25 char *__po; 26 }; 27 28 class socketstreambase : public virtual ios { 29 public: 30 socketstreambuf *rdbuf(); 31 32 protected: 33 socketstreambase(Socket *sock, streamsize n); 34 ~socketstreambase() {} 35 36 private: 37 socketstreambuf buf; 38 }; 39 40 inline socketstreambuf *socketstreambase::rdbuf() 41 { 42 return &this->buf; 43 } 44 45 class isocketstream : public socketstreambase, public istream { 46 public: 47 explicit isocketstream(Socket *sock, streamsize n = 4096); 48 virtual ~isocketstream(); 49 }; 50 51 52 class osocketstream : public socketstreambase, public ostream { 53 public: 54 explicit osocketstream(Socket *sock, streamsize n = 4096); 55 virtual ~osocketstream(); 56 }; 57 58 #endif // __SocketStream_H 59