Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of runtime TCP connect without ASIO one shot #3171

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/net/tcp_connection.pony
Original file line number Diff line number Diff line change
@@ -239,9 +239,15 @@ actor TCPConnection
_next_size = init_size
_max_size = max_size
_notify = consume notify
let asio_flags =
ifdef not windows then
AsioEvent.read_write_oneshot()
else
AsioEvent.read_write()
end
_connect_count =
@pony_os_connect_tcp[U32](this, host.cstring(), service.cstring(),
from.cstring())
from.cstring(), asio_flags)
_notify_connecting()

new ip4(
@@ -260,9 +266,15 @@ actor TCPConnection
_next_size = init_size
_max_size = max_size
_notify = consume notify
let asio_flags =
ifdef not windows then
AsioEvent.read_write_oneshot()
else
AsioEvent.read_write()
end
_connect_count =
@pony_os_connect_tcp4[U32](this, host.cstring(), service.cstring(),
from.cstring())
from.cstring(), asio_flags)
_notify_connecting()

new ip6(
@@ -281,9 +293,15 @@ actor TCPConnection
_next_size = init_size
_max_size = max_size
_notify = consume notify
let asio_flags =
ifdef not windows then
AsioEvent.read_write_oneshot()
else
AsioEvent.read_write()
end
_connect_count =
@pony_os_connect_tcp6[U32](this, host.cstring(), service.cstring(),
from.cstring())
from.cstring(), asio_flags)
_notify_connecting()

new _accept(
25 changes: 12 additions & 13 deletions src/libponyrt/lang/socket.c
Original file line number Diff line number Diff line change
@@ -552,7 +552,7 @@ static asio_event_t* os_listen(pony_actor_t* owner, int fd,
}

static bool os_connect(pony_actor_t* owner, int fd, struct addrinfo *p,
const char* from)
const char* from, uint32_t asio_flags)
{
map_any_to_loopback(p->ai_addr);

@@ -600,8 +600,7 @@ static bool os_connect(pony_actor_t* owner, int fd, struct addrinfo *p,
}

// Create an event and subscribe it.
asio_event_t* ev = pony_asio_event_create(owner, fd, ASIO_READ | ASIO_WRITE,
0, true);
asio_event_t* ev = pony_asio_event_create(owner, fd, asio_flags, 0, true);

if(!iocp_connect(ev, p))
{
@@ -619,8 +618,7 @@ static bool os_connect(pony_actor_t* owner, int fd, struct addrinfo *p,
}

// Create an event and subscribe it.
pony_asio_event_create(owner, fd, ASIO_READ | ASIO_WRITE | ASIO_ONESHOT, 0,
true);
pony_asio_event_create(owner, fd, asio_flags, 0, true);
#endif

return true;
@@ -661,7 +659,8 @@ static asio_event_t* os_socket_listen(pony_actor_t* owner, const char* host,
* in-flight, which may be 0.
*/
static int os_socket_connect(pony_actor_t* owner, const char* host,
const char* service, const char* from, int family, int socktype, int proto)
const char* service, const char* from, int family, int socktype, int proto,
uint32_t asio_flags)
{
bool reuse = (from == NULL) || (from[0] != '\0');

@@ -677,7 +676,7 @@ static int os_socket_connect(pony_actor_t* owner, const char* host,

if(fd != -1)
{
if(os_connect(owner, fd, p, from))
if(os_connect(owner, fd, p, from, asio_flags))
count++;
}

@@ -731,24 +730,24 @@ PONY_API asio_event_t* pony_os_listen_udp6(pony_actor_t* owner,
}

PONY_API int pony_os_connect_tcp(pony_actor_t* owner, const char* host,
const char* service, const char* from)
const char* service, const char* from, uint32_t asio_flags)
{
return os_socket_connect(owner, host, service, from, AF_UNSPEC, SOCK_STREAM,
IPPROTO_TCP);
IPPROTO_TCP, asio_flags);
}

PONY_API int pony_os_connect_tcp4(pony_actor_t* owner, const char* host,
const char* service, const char* from)
const char* service, const char* from, uint32_t asio_flags)
{
return os_socket_connect(owner, host, service, from, AF_INET, SOCK_STREAM,
IPPROTO_TCP);
IPPROTO_TCP, asio_flags);
}

PONY_API int pony_os_connect_tcp6(pony_actor_t* owner, const char* host,
const char* service, const char* from)
const char* service, const char* from, uint32_t asio_flags)
{
return os_socket_connect(owner, host, service, from, AF_INET6, SOCK_STREAM,
IPPROTO_TCP);
IPPROTO_TCP, asio_flags);
}

PONY_API int pony_os_accept(asio_event_t* ev)