Пример #1
0
INT32 _mongoSession::_processMsg( const CHAR *pMsg )
{
   INT32 rc  = SDB_OK ;
   INT32 tmp = SDB_OK ;
   INT32 bodyLen = 0 ;
   bson::BSONObjBuilder bob ;

   rc = _onMsgBegin( (MsgHeader *) pMsg ) ;
   if ( SDB_OK != rc )
   {
      goto error ;
   }

   {
      rc = getProcessor()->processMsg( (MsgHeader *) pMsg,
                                       _contextBuff, _replyHeader.contextID,
                                       _needReply ) ;
      bodyLen = _contextBuff.size() ;
      _replyHeader.numReturned = _contextBuff.recordNum() ;
      _replyHeader.startFrom = (INT32)_contextBuff.getStartFrom() ;
      _replyHeader.flags = rc ;
   }

   if ( rc  && ( 0 == bodyLen ) )
   {
      _errorInfo = engine::utilGetErrorBson( rc,
                   _pEDUCB->getInfo( engine::EDU_INFO_ERROR ) ) ;

      tmp = _errorInfo.getIntField( OP_ERRNOFIELD ) ;
      bob.append( "ok", FALSE ) ;
      bob.append( "code",  tmp ) ;
      bob.append( "errmsg", _errorInfo.getStringField( OP_ERRDESP_FIELD) ) ;
      _contextBuff = engine::rtnContextBuf( bob.obj() ) ;

      _replyHeader.numReturned = 1 ;
      _replyHeader.contextID = 0 ;
      _replyHeader.startFrom = 0 ;
      _replyHeader.flags = rc ;
   }

   _onMsgEnd( rc, (MsgHeader *) pMsg ) ;

done:
   return rc ;
error:
   goto done ;
}
Пример #2
0
INT32 _mongoSession::_processMsg( const CHAR *pMsg )
{
   INT32 rc  = SDB_OK ;
   INT32 tmp = SDB_OK ;
   INT32 bodyLen = 0 ;
   BOOLEAN needReply = FALSE ;
   bson::BSONObjBuilder bob ;
   mongoDataPacket &packet = _converter.getParser().dataPacket() ;

   rc = _onMsgBegin( (MsgHeader *) pMsg ) ;
   if ( SDB_OK != rc )
   {
      goto error ;
   }

   {
      rc = getProcessor()->processMsg( (MsgHeader *) pMsg,
                                       _contextBuff, _replyHeader.contextID,
                                       needReply ) ;
      _errorInfo = engine::utilGetErrorBson( rc,
                   _pEDUCB->getInfo( engine::EDU_INFO_ERROR ) ) ;
      if ( SDB_OK != rc )
      {
         tmp = _errorInfo.getIntField( OP_ERRNOFIELD ) ;
         bob.append( "ok", FALSE ) ;
         if ( SDB_IXM_DUP_KEY == tmp )
         {
            tmp = 11000 ;
         }
         bob.append( "code",  tmp ) ;
         bob.append( "errmsg", _errorInfo.getStringField( OP_ERRDESP_FIELD) ) ;
         bob.append( "err", _errorInfo.getStringField( OP_ERRDESP_FIELD) ) ;
         _contextBuff = engine::rtnContextBuf( bob.obj() ) ;
      }
      bodyLen = _contextBuff.size() ;
      _replyHeader.numReturned = _contextBuff.recordNum() ;
      _replyHeader.startFrom = (INT32)_contextBuff.getStartFrom() ;
      _replyHeader.flags = rc ;
   }

   if ( packet.with( OPTION_CMD ) )
   {
      if ( 0 == bodyLen )
      {
         tmp = _errorInfo.getIntField( OP_ERRNOFIELD ) ;
         if ( SDB_OK != rc )
         {
            bob.append( "ok", FALSE ) ;
            bob.append( "code",  tmp ) ;
            bob.append( "errmsg", _errorInfo.getStringField( OP_ERRDESP_FIELD) ) ;
            bob.append( "err", _errorInfo.getStringField( OP_ERRDESP_FIELD) ) ;
         }
         else
         {
            bob.append( "ok", TRUE ) ;
            bob.appendNull( "err" ) ;
         }

         _contextBuff = engine::rtnContextBuf( bob.obj() ) ;
         _replyHeader.flags = rc ;
      }
   }

   _onMsgEnd( rc, (MsgHeader *) pMsg ) ;

done:
   return rc ;
error:
   goto done ;
}