1. /**
    2. * Accept a SCTP connection from client
    3. * This call is blocked until it detects an incoming connection.
    4. *
    5. * @param A SCTPSocket address that is to be assigned with the accepted SCTPSocket object
    6. * @return Result of accepting the socket
    7. */
    8. bool usrSCTPServerSocket::accept(usrSCTPSocket*& newSocket)
    9. {
    10. struct sockaddr_in addr;
    11. socklen_t addr_len = (socklen_t)sizeof(struct sockaddr_in);
    12. memset(&addr,0,sizeof(struct sockaddr_in));
    13. struct socket *psock = usrsctp_accept(m_psock, (struct sockaddr *)&addr, &addr_len);
    14. if (psock == NULL)
    15. {
    16. ASN_DEBUG_STREAM_BEGIN(logger) << "Failed to accept SCTP socket with error: "
    17. ASN_DEBUG_STREAM_END(logger);
    18. return false;
    19. }
    20. newSocket = new usrSCTPSocket(psock);
    21. newSocket->m_localIP = m_localIP;
    22. newSocket->m_localPort = m_localPort;
    23. newSocket->m_peerIP = inet_ntoa(addr.sin_addr);
    24. newSocket->m_peerPort = ntohs(addr.sin_port);
    25. ASN_DEBUG(logger, "New SCTP socket has been accepted! IP: " << inet_ntoa(addr.sin_addr)<< "port: "<< ntohs(addr.sin_port));
    26. return true;
    27. }

    bool usrSCTPServerSocket::accept(usrSCTPSocket*& newSocket)

    该函数的参数为usrSCTPSocket*& newSocket, 调用的时候:

    SYS::usrSCTPSocket* psctpSocket = NULL;
    server->m_sctpServerSocket->accept(psctpSocket);

    参考:
    下面的这个代码中参数传递的是什么值? *&代表什么?
    在c语言和c++语言里都可以这么写吗?

    void InitStack(LNode &1st)
    {
    1st=(LNode
    )malloc(sizeof(LNode));
    1st->next=NULL;
    }

    这是C++的语法写法,&在形参中表示“引用”实参,
    LNode &lst ; 中LNode 是个整体,表示变量类型是LNode类指针, &lst中的&表明引用实参,即代表实参的一个别名。
    标准C是不支持这种写法的。

    追问:

    1. &不是取地址符吗? 引用参数是什么意思

    追答:

     **&在变量定义区,表示引用,要注意它的用法,**<br />**     &在变量操作区,表示取地址符**,如:
    
          int x=10, *p=&x ;  //这里&作用在x上, 是取地址符<br />          int &x  ;   //引用是C++引入的一个新特性,你要学的不是C++,则上述代码你是搞不懂的。 这里的&就表示引用。
    
                        //一般这种形式会在形参中出现。
    
      LNode * &lst ;  中LNode * 是个整体,表示变量类型是LNode类指针, &lst中的&表明引用实参,即代表实参的一个别名。 操作引用变量就相当于操作实参变量
    
    #include <iostream>  
    #include <cstdio>  
    #include <cstdlib>  
    #include <cstring>  
    using namespace std;;  
    
    const int N=31;  
    
    
    
    typedef struct BitNode  
    {  
        char value;  
        BitNode *lchild,*rchild;    
    }BitNode,*BiTree;  
    
    /*   *&代表什么?  
      这是C++的语法写法,&在形参中表示“引用”实参,
    LNode * &lst ;  中LNode * 是个整体,表示变量类型是LNode类指针, &lst中的&表明引用实参,即代表实参的一个别名。   
    标准C是不支持这种写法的。
    追问
    &不是取地址符吗? 引用参数是什么意思
    追答
    &在变量定义区,表示引用,要注意它的用法,
    &在变量操作区,表示取地址符,如:
    int x=10, *p=&x ;  //这里&作用在x上, 是取地址符
    int &x  ;   //引用是C++引入的一个新特性,你要学的不是C++,则上述代码你是搞不懂的。 这里的&就表示引用。 一般这种形式会在形参中出现。
    LNode * &lst ;  中LNode * 是个整体,表示变量类型是LNode类指针, &lst中的&表明引用实参,即代表实参的一个别名。 操作引用变量就相当于操作实参变量
     */
    
    void CreatTree(BitNode* &root,char *pre,int l1,int r1,char *in,int l2,int r2)  
    {  
        if(l1<=r1&&l2<=r2)  
        {  
            int key=pre[l1];  
            int midIndex=-1;  
            for(int i=l2;i<=r2;i++)  
            {  
                if(in[i]==key)  
                {  
                    midIndex=i;  
                    break;  
                }  
            }  
            root=(BitNode *)malloc(sizeof(BitNode));  
            root->value=key;  
            root->lchild=NULL;  
            root->rchild=NULL;  
            int llen=midIndex-l2;  
            CreatTree(root->lchild, pre, l1+1, l1+llen, in, l2, midIndex-1);  
            CreatTree(root->rchild, pre, l1+llen+1, r1, in, midIndex+1, r2);  
        }  
    }  
    
    void postOrderTraverse(BitNode *&root)  
    {  
        if(root->lchild)  
            postOrderTraverse(root->lchild);  
        if(root->rchild)  
            postOrderTraverse(root->rchild);  
        printf("%c",root->value);  
    }  
    
    int main()  
    {  
        char pre[N],in[N];  
        while(scanf("%s",pre)!=EOF)  
        {  
            scanf("%s",in);  
            int len1=strlen(pre);  
            int len2=strlen(in);  
            BitNode *root=NULL;  
            CreatTree(root,pre,0,len1-1,in,0,len2-1);  
            postOrderTraverse(root);  
            printf("\n");  
        }  
        return 0;  
    }