Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1008701
  • 博文数量: 327
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4319
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 11:21
文章存档

2011年(31)

2010年(139)

2009年(157)

我的朋友

分类: C/C++

2009-06-29 08:28:19

 

do
    {
        ZeroMemory(szProtoBuffer, sizeof(szProtoBuffer));

        pMsgHdr = ( PNFS_MSG_HEADER )szProtoBuffer ;

        ZeroMemory( pMsgHdr , sizeof( NFS_MSG_HEADER )) ;

        pMsgHdr->dwSignature = RNFS_MAGIC ;
        pMsgHdr->wProtocolVersion = RNFS_PROTOVERSION ;
        pMsgHdr->btPacketType = RNFS_DGRAM_REQUEST ;
        pMsgHdr->dwPacketLength = 0 ;
        pMsgHdr->wFunctionNum = RNFS_OPEN_SESSION ;
        pMsgHdr->dwAckNumber = dwAckNumber ;

        dwSize = MSG_HDR_LEN + pMsgHdr->dwPacketLength ;

        dwStatus = GU_SendAll(
                        SessionSocket ,
                        szProtoBuffer ,
                        dwSize ) ;
        if( 0 != dwStatus )
        {
            break ;
        }

        dwSize = MSG_HDR_LEN ;

        dwStatus = GU_RecvAll(
                        SessionSocket ,
                        szProtoBuffer,
                        dwSize ) ;
        if( 0 != dwStatus )
        {
            break ;
        }

        if( pMsgHdr->dwAckNumber != dwAckNumber )
        {
            dwStatus = ERROR_BAD_FORMAT ;
            break ;
        }
        
        if( pMsgHdr->dwRetStatus != 0 )
        {
            dwStatus = pMsgHdr->dwRetStatus ;
            break ;
        }

        dwSize = pMsgHdr->dwPacketLength ;

        dwStatus = GU_RecvAll(
                        SessionSocket ,
                        szProtoBuffer ,
                        dwSize ) ;
        if( 0 == dwStatus )
        {
            PNFS_SESSION pSession = ( PNFS_SESSION )szProtoBuffer ;
            * pdwSessionId = pSession->dwSessionId ;
        }
    } while( FALSE ) ;

 
开始觉得不是多此一举吗?仔细分析了以后,才发现很妙,因为在不同的条件判断中就可以按需break;从而达到最终执行到最后一个返回语句。而以前的实现都是以goto来实现的。
阅读(1605) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~