mirror of
https://github.com/Relintai/sfw.git
synced 2024-12-20 21:06:49 +01:00
Split set_non_block_and_close_on_exit() in Socket.
This commit is contained in:
parent
d2089a0ccb
commit
c853c76a68
@ -64,7 +64,7 @@ void Socket::close_socket() {
|
||||
}
|
||||
|
||||
// taken from muduo
|
||||
int Socket::set_non_block_and_close_on_exit() {
|
||||
int Socket::set_non_block() {
|
||||
ERR_FAIL_COND_V(_socket == 0, -1);
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
@ -85,10 +85,22 @@ int Socket::set_non_block_and_close_on_exit() {
|
||||
int ret = ::fcntl(_socket, F_SETFL, flags);
|
||||
// TODO check
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
// taken from muduo
|
||||
int Socket::set_close_on_exit() {
|
||||
ERR_FAIL_COND_V(_socket == 0, -1);
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
// TODO how to set FD_CLOEXEC on windows? is it necessary?
|
||||
return 0;
|
||||
#else
|
||||
// close-on-exec
|
||||
flags = ::fcntl(_socket, F_GETFD, 0);
|
||||
int flags = ::fcntl(_socket, F_GETFD, 0);
|
||||
flags |= FD_CLOEXEC;
|
||||
ret = ::fcntl(_socket, F_SETFD, flags);
|
||||
int ret = ::fcntl(_socket, F_SETFD, flags);
|
||||
// TODO check
|
||||
|
||||
return ret;
|
||||
|
@ -46,7 +46,8 @@ public:
|
||||
int set_reuse_port(bool on);
|
||||
void set_keep_alive(bool on);
|
||||
|
||||
int set_non_block_and_close_on_exit();
|
||||
int set_non_block();
|
||||
int set_close_on_exit();
|
||||
|
||||
int get_error();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user