cpp utils files, network and a smal util class
This commit is contained in:
parent
ea3dffdb4a
commit
62f50a2f79
13 changed files with 610 additions and 0 deletions
47
net/socketstream.cpp
Normal file
47
net/socketstream.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include "socketstream.h"
|
||||
using namespace zutil;
|
||||
|
||||
SocketStreamBuffer::SocketStreamBuffer(SocketIO &s) : soc(s){
|
||||
pBeg = pBuffer;
|
||||
pCur = pBuffer;
|
||||
pEnd = pBuffer;
|
||||
//pEnd = pBuffer + BUFFER_SIZE;
|
||||
streambuf::setp(pBeg, pEnd);
|
||||
|
||||
gBeg = gBuffer;
|
||||
gCur = gBuffer;
|
||||
gEnd = gBuffer + BUFFER_SIZE;
|
||||
streambuf::setg(gBeg, gCur, gEnd);
|
||||
}
|
||||
|
||||
int SocketStreamBuffer::underflow() {
|
||||
int recv_bytes = soc.read(gBuffer, BUFFER_SIZE);
|
||||
|
||||
if(recv_bytes > 0){
|
||||
gCur = gBuffer;
|
||||
gEnd = gBuffer+recv_bytes;
|
||||
streambuf::setg(gBeg, gCur, gEnd);
|
||||
|
||||
return Tr::not_eof( *gCur );
|
||||
}
|
||||
return Tr::eof();
|
||||
}
|
||||
|
||||
int SocketStreamBuffer::overflow(int c) {
|
||||
if(c == Tr::eof())
|
||||
return Tr::not_eof(c);
|
||||
soc.write(c);
|
||||
return c;
|
||||
/*if(sync() >= 0)
|
||||
return c;
|
||||
return Tr::eof();*/
|
||||
}/*
|
||||
int SocketStreamBuffer::sync() {
|
||||
if( soc.write( pBuffer, pCur-pBeg )){
|
||||
pCur = pBuffer;
|
||||
streambuf::setp(pBeg, pEnd);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue