#ifndef SOCKETSTREAM_H #define SOCKETSTREAM_H #include //streambuf #include //iostream #ifdef WIN32 #include #else #include //send,recv #include //send,recv #define SOCKET int #endif //Minimal implementation, thought when used //by a well writen iostream should be fast //thanks to xputn, xgetn. class socketbuf : public std::streambuf{ protected: const static int READBUF_SIZE=512; SOCKET sockfd; char readbuf[READBUF_SIZE]; public: socketbuf(SOCKET socketfd) { sockfd = socketfd; //using only the read buffer (because there is no other way) setg(readbuf,readbuf,readbuf);//set input buffer and mark it empty (start=cur=end) } virtual ~socketbuf(){} virtual int overflow(int c = EOF){ if(c != EOF) if(send(sockfd,(const char*)(&c),1,0) != 1) return EOF; return c; } virtual int underflow(){ if(gptr()!=0 && gptr()