Skip to content

Conversation

@mengps
Copy link

@mengps mengps commented Mar 6, 2023

1.修复传入 server port == 0 时 server_addr 不正确的端口, 并增加 ffrdp_getport() 获取临时端口号.
2.增加 ffrdp_peeksize() 接口用于确定待接收数据大小, 因为很多时候并非循环 recv().

printf("failed to bind !\n");
goto failed;
} else {
int len = sizeof (ffrdp->server_addr);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bind 不成功真有必要这样去做吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

呃, 我处理的是 else 情况,即绑定成功时候的处理。

}

void* ffrdp_init(char *ip, int port, char *txkey, char *rxkey, int server, int smss, int sfec)
void* ffrdp_init(const char *ip, int port, const char *txkey, const char *rxkey, int server, int smss, int sfec)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我不太习惯用 const,代码搞得复杂了,并且并不会带来什么好处。你的看法是?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为在C++11环境中, 字符串字面量为const char *, 这会引发一些警告

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个c代码本身编译不会报警告的,c++调用这个接口,增加一个类型转换 (char*)

return NULL;
}

int ffrdp_getport(void *ctxt)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果前面对 bind 失败的改动不是必须的,这个接口的增加也不是必须的了

return ret;
}

int ffrdp_peeksize(void *ctxt)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能说下什么场景会用到这个接口,因为我的测试程序里面,没有使用这个,也一样工作得挺正常。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在使用事件循环的场景中,通常做法是peeksize有数据时触发读取事件,而不会立即recv,所以需要一个这样的接口

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ffrdp_recv 是非阻塞的,其返回值已经实现了你所需的功能。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ffrdp_recv 返回值是 MIN(len, ffrdp->recv_size); 并不等同于 recv_size。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants