Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1146703
  • 博文数量: 177
  • 博客积分: 761
  • 博客等级: 上士
  • 技术积分: 1518
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-04 22:37
文章分类

全部博文(177)

文章存档

2017年(1)

2016年(3)

2015年(33)

2014年(48)

2013年(60)

2012年(32)

分类: C/C++

2014-05-26 14:35:42

 

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来实现的。
阅读(868) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~