当前位置: 首页>>代码示例>>C++>>正文


C++ Connection::Handler方法代码示例

本文整理汇总了C++中Connection::Handler方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::Handler方法的具体用法?C++ Connection::Handler怎么用?C++ Connection::Handler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection::Handler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Translate

// ------------------------------------------------------------------------
//  Translates raw byte data into telnet data, and may send it out to
//  the connection's current protocol handler
// ------------------------------------------------------------------------
void Telnet::Translate( Connection<Telnet>& p_conn, char* p_buffer, int p_size )
{
    for( int i = 0; i < p_size; i++ )
    {

        // if the character is a letter and the buffer isn't full,
        // add it to the buffer
        char c = p_buffer[i];
        if( c >= 32 && c != 127 && m_buffersize < BUFFERSIZE )
        {
            m_buffer[m_buffersize] = c;
            m_buffersize++;
        }

        // else check if it's a backspace
        else if( c == 8 && m_buffersize > 0 )
        {
            // erase the last character
            m_buffersize--;
        }

        // else check if it is a newline, meaning the line is complete
        else if( c == '\n' || c == '\r' )
        {
            // if the buffer size is more than 0, turn the buffer into
            // a string and send it off to the current handler of the 
            // connection. Then reset the size of the buffer.
            if( m_buffersize > 0 && p_conn.Handler() != 0 )
            {
                p_conn.Handler()->Handle( string( m_buffer, m_buffersize ) );
            }
            m_buffersize = 0;
        }
    }
}
开发者ID:JaguarMantid,项目名称:bettermud,代码行数:39,代码来源:Telnet.cpp

示例2: ClientThreadFunc

void sMiniFTPServer::ClientThreadFunc(sThread *t,void *user)
{
  Connection *c = (Connection *) user;
  sTCPSocket *socket = c->Socket;
  RequestInfo info;

  sVERIFYSTATIC(ServerBufferSize >= 16 && ServerBufferSize >= MAXREQUEST*2);
  sFixedArray<sU8> ioBuffer(ServerBufferSize);

  while(socket->IsConnected() && t->CheckTerminate())
  {
    // read request
    if(!socket->ReadAll(&ioBuffer[0],16))
      break;

    // "parse" it
    sU32 command;
    sInt filenameLen;
    sU64 extra;
    sUnalignedLittleEndianLoad32(&ioBuffer[0],command);
    sUnalignedLittleEndianLoad32(&ioBuffer[4],(sU32&) filenameLen);
    sUnalignedLittleEndianLoad64(&ioBuffer[8],extra);

    if(command > sMFC_LAST || filenameLen >= MAXREQUEST)
      break;

    // read the filename
    sString<MAXREQUEST> filename;
    if(!socket->ReadAll(&ioBuffer[0],filenameLen*2))
      break;

    // "parse" it
    for(sInt i=0;i<filenameLen;i++)
    {
      sU16 x;
      sUnalignedLittleEndianLoad16(&ioBuffer[i*2],x);
      filename[i] = x;
    }

    filename[filenameLen] = 0;

    // command-specific handling
    info.Command = (sMiniFTPCommand) command;
    info.Filename = filename;
    info.File = 0;
    info.DirListing.Clear();

    ioBuffer[0] = sU8(c->Handler(info) ? sMFE_OK : sMFE_NOSUCHFILE);
    sBool ok = socket->WriteAll(&ioBuffer[0],1);

    if(ok && ioBuffer[0] == sMFE_OK) // output processing (depends on command)
    {
      ok = sFALSE;

      switch(command)
      {
      case sMFC_EXISTS:
      case sMFC_DELETE:
        ok = sTRUE;
        break;

      case sMFC_GET:
        {
          sSize size = info.File->GetSize();

          sUnalignedLittleEndianStore64(&ioBuffer[0],size);
          if(socket->WriteAll(&ioBuffer[0],8) && info.File->SetOffset(extra))
          {
            sSize pos = extra;
            while(pos<size)
            {
              sInt bytes = (sInt) sMin<sS64>(size-pos,ioBuffer.GetSize());
              if(!info.File->Read(&ioBuffer[0],bytes)
                || !socket->WriteAll(&ioBuffer[0],bytes))
                break;

              pos += bytes;
            }

            ok = (pos == size);
          }
        }
        break;

      case sMFC_PUT:
        {
          sSize size;
          if(c->OnlyFullFiles && extra != 0)
            break;

          if(!socket->ReadAll(&ioBuffer[0],8))
            break;

          sUnalignedLittleEndianLoad64(&ioBuffer[0],(sU64&) size);
          if(info.File->SetOffset(extra))
          {
            sSize pos = extra;
            while(pos<size)
            {
              sInt bytes = (sInt) sMin<sS64>(size-pos,ioBuffer.GetSize());
//.........这里部分代码省略.........
开发者ID:Ambrevar,项目名称:fr_public,代码行数:101,代码来源:miniftp.cpp


注:本文中的Connection::Handler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。