C ++ usrsctp回调参数为null [英] C++ usrsctp callback parameters null

查看:1149
本文介绍了C ++ usrsctp回调参数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个网络应用程序,在windows上使用usrsctp库,我有一个奇怪的问题,参数显示为null,当他们不应该在回调函数。我不知道这是一个特定的usrsctp问题或一些我做错了,所以我想先检查这里。

I'm currently creating a network application that uses the usrsctp library on windows and I'm having an odd problem with parameters appearing as null when they shouldn't be on a callback function. I'm not sure if this is a specific usrsctp issue or something I'm doing wrong so I wanted to check here first.

当创建一个新的sctp套接字时,您传递一个函数作为您希望在收到数据时调用的参数之一,如下面的代码所示

When creating a new sctp socket you pass a function as one of the parameters that you want to be called when data is received as shown in the code below

static int receive_cb(struct socket *sock, union sctp_sockstore addr, void *data,
size_t datalen, struct sctp_rcvinfo rcv, int flags, void *ulp_info)
{
    if (data == NULL) {
        printf("receive_cb - Data NULL, closing socket...\n");
        done = 1;
        usrsctp_close(sock);
    }
    else {
        _write(_fileno(stdout), data, datalen);
        free(data);
    }
    return (1);
}

...
//Create SCTP socket
if ((sctpsock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, receive_cb, NULL, 0, NULL)) == NULL) {
    perror("usrsctp_socket");
    return -1;
}

通过库跟踪我可以看到在回调之前调用所有参数正确

Tracing through the library I can see that before the call back is called all the parameters are correct

一旦我进入它,它们就变成了null

As soon as I step into it they become null

我不知道会导致什么,回调函数直接从官方示例中获取没有什么应该错在那里。

I've no idea what would cause this, the callback function was taken straight from the official examples so nothing should be wrong there.

推荐答案

确定,解决了问题,似乎'union sctp_sockstore addr'之前的参数导致堆栈被推by 0x1c并将其余的参数从他们应该在的地方移开。我从来没有遇到这个问题,但将参数更改为指针固定它。

Ok, worked out the issue, it seems that the parameter before 'union sctp_sockstore addr' was causing the stack to be pushed by 0x1c and moving the rest of the parameters away from where they should be. I've never come across this issue before but changing the parameter to a pointer fixed it.

这篇关于C ++ usrsctp回调参数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆