本文整理汇总了C++中DataBuffer::getLength方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer::getLength方法的具体用法?C++ DataBuffer::getLength怎么用?C++ DataBuffer::getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBuffer
的用法示例。
在下文中一共展示了DataBuffer::getLength方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendTransparentMsg
/*发送透明传输数据*/
bool CVechileMgr::SendTransparentMsg(_stVechile *p , int ncount,unsigned short wType)
{
if( ncount <= 0 ) {
return false ;
}
DataBuffer transport_buf;
TransHeader header;
int nLen = _logistics->BuildTransportData(wType,transport_buf);
OUT_HEX(NULL, 0, "Transport", transport_buf.getBuffer(),transport_buf.getLength());
BuildHeader(header.header, 0x900,nLen, p);
DataBuffer sendbuf;
sendbuf.writeBlock(&header, sizeof(header));
sendbuf.writeBlock(transport_buf.getBuffer(), transport_buf.getLength());
unsigned short mlen = (sendbuf.getLength()-sizeof(GBheader)) & 0x03FF ;
sendbuf.fillInt16( mlen, 3 ) ;
GBFooter footer ;
sendbuf.writeBlock(&footer, sizeof(footer) ) ;
if ( ! Send5BData( p->fd_, sendbuf.getBuffer(), sendbuf.getLength() ) ) {
p->car_state_ = OFF_LINE ;
return false ;
}
p->lgs_time_ = share::Util::currentTimeUsec() ;
return true ;
}
示例2: HandleInnerData
void MsgClient::HandleInnerData( socket_t *sock, const char *data, int len )
{
User user = _online_user.GetUserBySocket( sock ) ;
if ( user._user_id.empty() ) {
OUT_ERROR( sock->_szIp, sock->_port, "CAIS" , "find fd %d user failed, data %s", sock->_fd, data ) ;
return ;
}
user._last_active_time = time(NULL) ;
_online_user.SetUser( user._user_id, user ) ;
string line( data, len ) ;
vector<string> vec ;
if ( ! splitvector( line, vec, " " , 6 ) ){
OUT_ERROR( sock->_szIp, sock->_port, user._user_name.c_str() , "fd %d data error: %s", sock->_fd, data ) ;
return ;
}
DataBuffer buf ;
string head = vec[0] ;
string seqid = vec[1] ;
string macid = vec[2] ;
string code = vec[3] ; // 通信码,对于点名数据的区分
string cmd = vec[4] ;
string val = vec[5] ;
if ( head == "CAITS" ) {
if( cmd == "U_REPT" ){
// 上报类消息处理
_convert->convert_urept( macid , val , buf , ( code == "201") ) ;
} else if( cmd == "D_CTLM" ) {
// ToDo: 控制类消息处理
} else if( cmd == "D_SNDM" ) {
// ToDo : 消息发送的处理
} else {
OUT_WARNING( sock->_szIp, sock->_port, user._user_name.c_str() , "except message:%s", (const char*)data ) ;
}
} else {
// 处理通应应答消息
_convert->convert_comm( seqid, macid, val, buf ) ;
}
if( buf.getLength() > 0 ) {
// 添加用户会话中
_session.AddSession( macid, user._user_id ) ;
// 发送指定的地区用户
_pEnv->GetPasClient()->HandleData( buf.getBuffer(), buf.getLength() ) ;
}
}
示例3: sendIOControl
/**
* Send an I/O control request to the Alfresco CIFS server, receive and validate the response
*
* @param ctlCode const unsigned int
* @param reqbuf DataBuffer&
* @param respbuf DataBuffer&
*/
void AlfrescoInterface::sendIOControl( const unsigned int ctlCode, DataBuffer& reqbuf, DataBuffer& respbuf) {
// Send the I/O control request, receive the response
DWORD retLen = 0;
BOOL res = DeviceIoControl( m_handle, ctlCode, reqbuf.getBuffer(), reqbuf.getLength(),
respbuf.getBuffer(), respbuf.getBufferLength(), &retLen, (LPOVERLAPPED) NULL);
if ( res) {
// Validate the reply signature
if ( retLen >= IOSignatureLen) {
respbuf.setLength(retLen);
respbuf.setEndOfBuffer();
String sig = respbuf.getString(IOSignatureLen, false);
if ( sig.equals(IOSignature) == false)
throw Exception( L"Invalid I/O control signature received");
}
}
else
throw Exception( L"Send I/O control error", Integer::toString( GetLastError()));
}
示例4: HandleQueue
//-----------------------------缓存数据处理接口-----------------------------------------
// 处理外部数据
int PasServer::HandleQueue(const char *uid, void *buf, int len, int msgid)
{
OUT_PRINT( NULL, 0, NULL, "HanldeQueue msg id %d , accesscode %s , data length %d" , msgid, uid, len );
switch (msgid) {
case DATA_FILECACHE: // 用户不在线数据缓存
{
// 如果数据长度不正确直接返回
if (len < (int) sizeof(Header)) {
OUT_ERROR( NULL, 0, NULL, "HandleQueue filecache data length %d error", len );
return IOHANDLE_ERRDATA;
}
OUT_PRINT( NULL, 0, NULL, "HandleQueue %s" , _proto_parse.Decoder( (const char *)buf, len ).c_str() );
Header *header = (Header *) buf;
unsigned short msg_type = ntouv16(header->msg_type);
// 如果不为扩展类消息
if (msg_type != DOWN_EXG_MSG) {
return IOHANDLE_ERRDATA;
}
// 如果为扩展类消息
ExgMsgHeader *exg = (ExgMsgHeader*) ((const char *) (buf) + sizeof(Header));
unsigned short data_type = ntouv16( exg->data_type );
if (data_type != DOWN_EXG_MSG_CAR_LOCATION) {
return IOHANDLE_ERRDATA;
}
DownExgMsgCarLocation *req = (DownExgMsgCarLocation *) buf;
DownExgMsgHistoryArcossareaHeader msg;
memcpy(&msg, buf, sizeof(msg));
msg.exg_msg_header.data_length = ntouv32( sizeof(char) + sizeof(GnssData) );
msg.exg_msg_header.data_type = ntouv16(DOWN_EXG_MSG_HISTORY_ARCOSSAREA);
msg.header.msg_len = ntouv32( sizeof(msg) + sizeof(char) + sizeof(GnssData) + sizeof(Footer) );
msg.cnt_num = 0x01;
DataBuffer dbuf;
dbuf.writeBlock(&msg, sizeof(msg));
dbuf.writeBlock(&req->gnss, sizeof(GnssData));
Footer footer;
dbuf.writeBlock(&footer, sizeof(footer));
if (!SendDataToPasUser(atoi(uid), dbuf.getBuffer(), dbuf.getLength())) {
OUT_ERROR( NULL, 0, NULL, "DOWN_EXG_MSG_HISTORY_ARCOSSAREA:%s" , msg.exg_msg_header.vehicle_no );
return IOHANDLE_FAILED;
}
OUT_SEND( NULL, 0, NULL, "DOWN_EXG_MSG_HISTORY_ARCOSSAREA:%s" , msg.exg_msg_header.vehicle_no );
}
break;
}
return IOHANDLE_SUCCESS;
}
示例5: ProcessResp
// 处理下载的后的图片数据
void MsgClient::ProcessResp( unsigned int seqid, const char *data, const int nlen , const int err )
{
// 处理数据
if ( data == NULL || err != HTTP_CALL_SUCCESS || nlen == 0 ) {
OUT_ERROR( NULL, 0, "Pic" , "pic seqid %u, error %d" , seqid, err ) ;
return ;
}
/**
char szfile[128] = {0};
sprintf( szfile, "./%u.jpg", seqid ) ;
WriteFile( szfile, data, nlen ) ;
OUT_INFO( NULL, 0, "PHOTO", "write file %s length %d", szfile, nlen ) ;
*/
char szKey[512] = {0} ;
_pEnv->GetCacheKey( seqid, szKey ) ;
int dlen = 0 ;
char *msg = _pEnv->GetMsgCache()->GetData( szKey, dlen ) ;
if ( msg == NULL ) {
OUT_ERROR( NULL, 0, "Pic" , "pic get key %s cache failed" , szKey ) ;
return ;
}
// 转换照片的结构体
UpCtrlMsgTakePhotoAck *ack = ( UpCtrlMsgTakePhotoAck * ) msg;
int len = sizeof(UpCtrlMsgTakePhotoAck) + sizeof(Footer) + nlen ;
ack->header.msg_len = ntouv32( len ) ;
ack->ctrl_msg_header.data_length = ntouv32( sizeof(UpCtrlMsgTakePhotoBody) + nlen ) ;
ack->ctrl_photo_body.photo_len = ntouv32( nlen ) ;
DataBuffer dbuf ;
dbuf.writeBlock( ack, sizeof(UpCtrlMsgTakePhotoAck) ) ;
if ( nlen > 0 ) {
dbuf.writeBlock( data, nlen ) ;
}
Footer footer ;
dbuf.writeBlock( &footer, sizeof(footer) ) ;
// 取得接入码信息
unsigned int accesscode = ntouv32( ack->header.access_code ) ;
// 发送拍照的照片数据
_pEnv->GetPasClient()->HandlePasUpData( accesscode, dbuf.getBuffer(), dbuf.getLength() ) ;
OUT_SEND( NULL, 0, NULL, "UP_CTRL_MSG_TAKE_PHOTO_ACK:%s, picture length %d", ack->ctrl_msg_header.vehicle_no , nlen ) ;
_pEnv->GetMsgCache()->FreeData( msg ) ;
}
示例6: sizeof
//.........这里部分代码省略.........
} else {
// 将获到GPS位置数据填充入结构体中
convert_gps_info( map, ack->ctrl_photo_body.gps ) ;
}
// 从本地读取一次图片
int piclen = 0 ;
char *picdata = NULL ;
// 如果本地图片路径为空就从HTTP取图片
if ( ! _picdir.empty() ) {
char szpath[1024] = {0};
sprintf( szpath, "%s/%s", _picdir.c_str(), temp.c_str() ) ;
picdata = ReadFile( szpath , piclen ) ;
}
// 如果文件在本机直接读取
if ( picdata != NULL && piclen > 0 ) {
// 直接从本机读取图片
ack->header.msg_len = ntouv32( sizeof(UpCtrlMsgTakePhotoAck) + sizeof(Footer) + piclen ) ;
ack->ctrl_msg_header.data_length = ntouv32( sizeof(UpCtrlMsgTakePhotoBody) + piclen ) ;
ack->ctrl_photo_body.photo_len = ntouv32( piclen ) ;
DataBuffer dbuf ;
dbuf.writeBlock( ack, sizeof(UpCtrlMsgTakePhotoAck) ) ;
if ( piclen > 0 ) {
dbuf.writeBlock( picdata, piclen ) ;
}
Footer footer ;
dbuf.writeBlock( &footer, sizeof(footer) ) ;
// 取得接入码信息
unsigned int accesscode = ntouv32( ack->header.access_code ) ;
// 发送拍照的照片数据
_pEnv->GetPasClient()->HandlePasUpData( accesscode, dbuf.getBuffer(), dbuf.getLength() ) ;
FreeBuffer( picdata ) ;
OUT_SEND( NULL, 0, NULL, "UP_CTRL_MSG_TAKE_PHOTO_ACK:%s, picture length %d, path: %s",
ack->ctrl_msg_header.vehicle_no , nlen , temp.c_str() ) ;
} else { // 从网络读取文件
// 取得新序号的ID值
unsigned int seqid = _pEnv->GetSequeue() ;
_pEnv->GetCacheKey( seqid, szKey ) ;
// 重新放入新序号队列中
_pEnv->GetMsgCache()->AddData( szKey, pbuf , nlen ) ;
// 从网络中读取图片数据
((IMsgClient*)_pEnv->GetMsgClient())->LoadUrlPic( seqid , temp.c_str() ) ;
OUT_SEND( NULL, 0, NULL, "UP_CTRL_MSG_TAKE_PHOTO_ACK picture path %s", temp.c_str() ) ;
}
_pEnv->GetMsgCache()->FreeData( pbuf ) ;
}
break ;
/*
case 5: {
int result = 0;
if (!get_map_integer(map, "18", result) || result != 1) {
return NULL;
}
UpExgMsgRegister msg;
msg.header.msg_seq = ntouv32(_seq_gen.get_next_seq());
msg.header.msg_len = ntouv32(sizeof(UpExgMsgRegister));
msg.header.msg_type = ntouv16(UP_EXG_MSG);
msg.exg_msg_header.data_type = ntouv16(UP_EXG_MSG_REGISTER); //子业务类型
示例7: SendLocationPic
// 发送图片数据
bool CVechileMgr::SendLocationPic( _stVechile *p , int ncount )
{
if( ncount <= 0 || p == NULL )
return false ;
if ( access( _pic_url.c_str(), 0 ) != 0 ) {
OUT_ERROR( NULL, 0, NULL, "check pic dir %s failed", _pic_url.c_str() ) ;
return false ;
}
int photo_len = 0 ;
char *pfile = ReadFile( _pic_url.c_str() , photo_len ) ;
GBFooter footer ;
GBheader header ;
header.msgid = htons(0x0801) ;
memcpy( header.car_id , p->car_id_ , sizeof(header.car_id) ) ;
MediaUploadBody body ;
body.id = 1 ;
body.type = 0 ;
body.mtype = 0 ;
body.event = 1 ;
body.chanel = 1 ;
unsigned int alarm = 0 ;
memcpy( &body.gps.alarm, &alarm, sizeof(unsigned int) ) ;
unsigned int state = 0 ;
memcpy( &body.gps.state , &state, sizeof(unsigned int) ) ;
int pos = p->gps_pos_ ;
pos = ++ pos % ncount ;
Point &pt = _gps_vec[pos] ;
body.gps.heigth = htons(100) ;
body.gps.speed = htons(get_car_speed());//htons(60) ;
body.gps.direction = htons(0) ;
if(body.gps.speed == 0) {
body.gps.state.bit0 = 0;
body.gps.state.bit1 = 0;
body.gps.longitude = 0 ;
body.gps.latitude = 0 ;
} else {
body.gps.state.bit0 = 1;
body.gps.state.bit1 = 1;
body.gps.longitude = htonl( pt.lon ) ;
body.gps.latitude = htonl( pt.lat ) ;
}
// 取得当前BCD的时间
get_bcd_time( body.gps.date_time ) ;
DataBuffer buffer ;
buffer.writeBlock( &body, sizeof(body) ) ;
buffer.writeBlock( pfile, photo_len ) ;
FreeBuffer( pfile ) ;
// 取得需要发送的数据体
char *ptr = buffer.getBuffer() ;
int len = buffer.getLength() ;
// 计算分包数
int count = ( len / MAX_SPLITPACK_LEN ) + ( ( len % MAX_SPLITPACK_LEN == 0 && len > 0 ) ? 0 : 1 ) ;
int offset = 0 , left = len , readlen = 0 ;
// 根据分包的序号需要连续处理
unsigned short seqid = 0 ;
{
_seq_mutex.lock() ;
p->seq_id_ = p->seq_id_ + count ;
if ( p->seq_id_ < count ) {
p->seq_id_ = count + 1 ;
seqid = 1 ;
} else {
seqid = p->seq_id_ - count ;
}
_seq_mutex.unlock() ;
}
// 发送FD的数据
socket_t *fd = ( p->ufd_ != NULL ) ? p->ufd_ : p->fd_ ;
// 处理分包发送数据
for ( int i = 0 ; i < count; ++ i ) {
// 计算能处理长度
readlen = ( left > MAX_SPLITPACK_LEN ) ? MAX_SPLITPACK_LEN : left ;
// 长度为消息内容的长度去掉头和尾
unsigned short mlen = 0 ;
if ( count > 1 ) { // 如果为多包数据,需要设置分包位标志
mlen = htons( ( readlen & 0x23FF ) | 0x2000 ) ;
} else {
mlen = htons( readlen & 0x03FF ) ;
}
memcpy( &(header.msgtype), &mlen, sizeof(short) );
unsigned short downseq = seqid + i + 1 ;
//.........这里部分代码省略.........
示例8: SendLocationPos
//.........这里部分代码省略.........
header.gpsinfo.state.bit6 = 1;
header.gpsinfo.state.bit7 = 1;
header.gpsinfo.longitude = htonl( pt.lon ) ;
header.gpsinfo.latitude = htonl( pt.lat ) ;
}
buf.writeBlock( &header, sizeof(header) ) ;
// 需要上传CAN的数据
if ( now - p->last_candata_ > _candata_time && _candata_time > 0 ) {
p->last_candata_ = now ;
int index = nrand % 5;
write_dword( buf, 0x01, 2000 ) ;
write_word( buf, 0x02, 100 ) ;
write_word( buf, 0x03, 800 ) ;
if ( index != 0 ) {
struct _B1{
unsigned char cmd ;
unsigned int val ;
};
_B1 b1 ;
b1.cmd = ( index - 1 ) ;
b1.val = htonl( nrand ) ;
write_block( buf, 0x11, (unsigned char*)&b1 , sizeof(_B1) ) ;
} else {
write_byte( buf, 0x11, 0 ) ;
}
if ( nrand % 2 == 0 ) {
struct _B2{
unsigned char type;
unsigned int val ;
unsigned char dir ;
};
_B2 b2 ;
b2.type = (( index + 1 ) % 5 ) ;
b2.val = htonl( index ) ;
b2.dir = ( index%2 == 0 ) ;
write_block( buf, 0x12, (unsigned char*)&b2, sizeof(_B2) ) ;
}
if ( nrand % 3 == 0 ) {
struct _B3{
unsigned int id ;
unsigned short time ;
unsigned char result ;
};
_B3 b3 ;
b3.id = htonl( index ) ;
b3.time = htons( nrand % 100 ) ;
b3.result = ( index % 2 == 0 ) ;
write_block( buf , 0x13, (unsigned char*)&b3, sizeof(_B3) ) ;
}
switch( index ) {
case 0:
write_word( buf, 0x20, nrand ) ;
write_word( buf, 0x21, nrand % 100 ) ;
write_word( buf, 0x22, nrand % 1000 ) ;
write_word( buf, 0x23, nrand % 80 ) ;
case 1:
write_dword( buf, 0x24, nrand % 157887 ) ;
write_dword( buf, 0x25, nrand % 233555 ) ;
write_dword( buf, 0x26, nrand % 200 ) ;
write_dword( buf, 0x40, nrand % 3000 ) ;
case 2:
write_word( buf, 0x41, nrand % 130 ) ;
write_word( buf, 0x42, nrand % 120 ) ;
write_word( buf, 0x43, nrand % 200 ) ;
write_word( buf, 0x44, nrand % 300 ) ;
case 3:
write_word( buf, 0x45, nrand % 150 ) ;
write_word( buf, 0x46, nrand % 100 ) ;
case 4:
write_word( buf, 0x47, nrand % 150 ) ;
write_word( buf, 0x48, nrand % 200 ) ;
break ;
}
}
// 长度为消息内容的长度去掉头和尾
unsigned short mlen = (buf.getLength()-sizeof(GBheader)) & 0x03FF ;
buf.fillInt16( mlen, 3 ) ;
GBFooter footer ;
buf.writeBlock( &footer, sizeof(footer) ) ;
if ( Send5BData( p->fd_, buf.getBuffer(), buf.getLength() ) ) {
p->gps_pos_ = pos ;
return true ;
}
p->car_state_ = OFF_LINE ;
// 发送位置包
return false ;
}
示例9: HandleOnePacket
//.........这里部分代码省略.........
PlatFormCommonResp *resp = ( PlatFormCommonResp *) data ;
unsigned short rsp_msgid = ntohs( resp->resp.resp_msg_id ) ;
if ( rsp_msgid == 0x0102 ) { // 如果是终端鉴权
if ( resp->resp.result == 0x00 ) {
if ( sock->_ptr != NULL ) {
// 将离线用户转为在线用户
((_stVechile*)sock->_ptr)->car_state_ = ON_LINE ;
}
// 记录登陆日志
OUT_CONN( ip , port, str_car_id.c_str() , "Term auth success , fd %d" , sock->_fd ) ;
}
}
}
else if (msg_id == 0x8900) //数据下行透传
{
const int data_len = msg_len - 3 ;
if ( data_len <= 0 ) {
OUT_ERROR( ip, port, str_car_id.c_str(), "transparent transmission length zero, data len: %d", data_len ) ;
return;
}
if (data[sizeof(TransHeader)] == 0x01){ //透传类型
DataBuffer pBuf;
int nLength = _logistics->ParseTransparentMsgData((unsigned char *)&data[sizeof(TransHeader)+1],
data_len-1,pBuf);
if (nLength >0){ //下发返回
TermCommonResp req ;
int nlen = sizeof(TermCommonResp) ;
req.header.msgid = htons( 0x0001 ) ;
req.header.seq = header->seq ;
memcpy( req.header.car_id , header->car_id , sizeof(req.header.car_id ) ) ;
unsigned short dlen = nlen - sizeof(GBheader) - sizeof(GBFooter) ;
dlen = htons( dlen & 0x03FF ) ;
memcpy( &req.header.msgtype , &dlen , sizeof(short) ) ;
req.resp.resp_msg_id = htons( msg_id ) ;
req.resp.resp_seq = header->seq ;
req.resp.result = 0x00 ;
// 其它统一发送通用应答
Send5BData( sock, (const char *)&req, sizeof(req));
DataBuffer repBuffer;
TransHeader theader;
GBFooter footer;
theader.header.msgid = htons(0x0900);
theader.header.seq = header->seq;
unsigned short mlen = (unsigned short)pBuf.getLength();
mlen = htons( mlen & 0x03FF ) ;
memcpy( &theader.header.msgtype , &mlen , sizeof(short) ) ;
memcpy(theader.header.car_id,header->car_id , sizeof(req.header.car_id));
repBuffer.writeBlock(&theader,sizeof(theader));
repBuffer.writeBlock(pBuf.getBuffer(),pBuf.getLength());
repBuffer.writeBlock(&footer,sizeof(footer));
Send5BData( sock ,repBuffer.getBuffer(),repBuffer.getLength());//发送物流通用应答
}
}
}
else
{
TermCommonResp req ;
int nlen = sizeof(TermCommonResp) ;
req.header.msgid = htons( 0x0001 ) ;
req.header.seq = header->seq ;
memcpy( req.header.car_id , header->car_id , sizeof(req.header.car_id ) ) ;
unsigned short dlen = nlen - sizeof(GBheader) - sizeof(GBFooter) ;
dlen = htons( dlen & 0x03FF ) ;
memcpy( &req.header.msgtype , &dlen , sizeof(short) ) ;
req.resp.resp_msg_id = htons( msg_id ) ;
req.resp.resp_seq = header->seq ;
req.resp.result = 0x00 ;
if ( msg_id == 0x8801 ) {
if ( sock->_ptr != NULL ) {
OUT_PRINT( NULL, 0, NULL, "add pic %s", str_car_id.c_str() ) ;
// 添加需要发送拍图片请求中
_piclist.push_back( ( _stVechile*)sock->_ptr ) ;
_picmonitor.notify() ;
}
}
// 其它统一发送通用应答
Send5BData( sock, (const char *)&req, sizeof(req) ) ;
}
// 记录发送数据
_bench.IncBench( BENCH_MSGRECV ) ;
}
示例10: sizeof
// 添加内存数据
bool CPackMgr::CMemFile::AddBuffer( DataBuffer &pack, const int index, const int count, const char *buf, int len )
{
// 如果为一个数据就不需要处理组包了
if ( count == 1 ) {
pack.writeBlock( buf, len ) ;
return true ;
}
// 如果还没有开辟数据空间
if ( _vec.empty() ) {
for ( int i = 0; i < count; ++ i ) {
_vec.push_back( new DataBuffer ) ;
}
}
// 如果不正确的INDEX就不处理了
if ( index > (int) _vec.size() ) {
return false ;
}
// 取得存放数据块的内存
DataBuffer *p = _vec[index-1] ;
assert( p != NULL ) ;
if ( p->getLength() == 0 ) {
++ _cur ;
} else {
p->resetBuf() ;
}
p->writeBlock( buf, len ) ;
// 如果接收数据包成功
if ( _cur >= (unsigned int) count ) {
// 取得分包个数
int size = _vec.size() ;
// 写最后一个数据包的头部
pack.writeBlock( p->getBuffer() , sizeof(GBheader) ) ;
// 重新开始组包,这样数据就只有数据头和数据体
for ( int i = 0; i < size ; ++ i ) {
p = _vec[i] ;
if ( p->getLength() < (int)sizeof(GBheader) ){
continue ;
}
unsigned short mlen = p->fetchInt16( 3 ) & 0x03FF;
if ( mlen > 0 ) {
pack.writeBlock( p->getBuffer() + sizeof(GBheader) + 4 , mlen ) ;
}
}
// 添加尾部数据
GBFooter footer ;
pack.writeBlock( &footer, sizeof(footer) ) ;
return true ;
}
// 更新最后一次访问的时间
_last = time(NULL) ;
OUT_INFO( NULL, 0, "packmgr" , "save index file %d, current count %d total %d" , index, _cur, count ) ;
return false ;
}
示例11: testSocket
// ---------------------------------------------
void testSocket(string ip, unsigned short port) {
Socket* socket = new Socket("null", 0);
Socket::InetAddressPort remoteAddrAndPort;
remoteAddrAndPort.port = port;
Socket::getSockaddrByIpAndPort(&remoteAddrAndPort.addr, ip, port);
socket->makeNonBlocking();
while (true) {
bool result = socket->connect(remoteAddrAndPort);
if (result) {
cout << "connect success!" << endl;
cm::Thread::sleep(100);
char sendData[] = "TCP client request";
int numberOfBytesSent;
if (SKT_SUCC == socket->send(sendData, strlen(sendData), numberOfBytesSent)) {
assert(numberOfBytesSent == strlen(sendData));
cout << "send " << numberOfBytesSent << " bytes data complete" << endl;
DataBuffer* response = new DataBuffer();
int numOfBytesRecved = 0;
while (true) {
result = socket->recv(response->getEndOfDataPointer(), response->getSize() - response->getLength(), numOfBytesRecved);
assert(result != SKT_ERR);
if (result == SKT_SUCC) {
assert(numOfBytesRecved != 0);
response->increaseDataLength(numOfBytesRecved);
cout << "recv " << numOfBytesRecved << " bytes data: " << response->getData() << endl;
response->reset();
break;
} else {
cm::Thread::sleep(1);
}
}
}
socket->close();
break;
} else {
cm::Thread::sleep(1);
}
}
}