private:
~DBI_Input_Handler(){}
ACE_SOCK_Stream peer_;
};
int DBI_Input_Handler::handle_input(ACE_HANDLE) {
vector<char> v_line;
int res;
if((res = SockStreamOp::getLine(peer_,v_line)) <= 0) {
ACE_DEBUG((LM_ERROR,"[%D][%t][%M][%N:%l]getLine:%d error,close the connection\n",res));
disconnect();
/*
return -1 to detach the event handler from the reactor.
*/
return -1;
}
for(int i=0; i < v_line.size(); i++) {
printf("%x ",(0xff &buf[i]));
}
return 0;
}
SocketStreamOP 设计:
class SockStreamOp {
public:
static int send(ACE_SOCK_Stream &peer,char *buf,int size,const ACE_Time_Value *timeout = 0) {
return peer.send_n(buf,size,timeout);
}
static int recv(ACE_SOCK_Stream &peer,char* buf,int size,const ACE_Time_Value *timeout = 0) {
return peer.recv_n(buf,size,timeout);
}
static int getLine(ACE_SOCK_Stream &peer,VC &v,UINT32 max=1024) {
char buf[1] ;
int res = 0;
int count = 0;
|