Skip to content

Commit

Permalink
Less memory allocation in happyeyeballs_connect
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Sustrik <[email protected]>
  • Loading branch information
sustrik committed Oct 30, 2018
1 parent 52df2b3 commit 16f0fcd
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions happyeyeballs.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ static dill_coroutine void dill_happyeyeballs_coordinator(
parallel. Create two coroutines and two channels to pass
the addresses from them. */
int chipv6[2];
rc = dill_chmake(chipv6);
struct dill_chstorage chipv6_storage;
rc = dill_chmake_mem(&chipv6_storage, chipv6);
dill_assert(rc == 0);
int chipv4[2];
rc = dill_chmake(chipv4);
struct dill_chstorage chipv4_storage;
rc = dill_chmake_mem(&chipv4_storage, chipv4);
dill_assert(rc == 0);
int bndl = dill_bundle();
struct dill_bundle_storage bndl_storage;
int bndl = dill_bundle_mem(&bndl_storage);
dill_assert(bndl >= 0);
rc = dill_bundle_go(bndl, dill_happyeyeballs_dnsquery(name, port,
DILL_IPADDR_IPV6, chipv6[1]));
Expand Down Expand Up @@ -150,19 +153,17 @@ int dill_happyeyeballs_connect(const char *name, int port, int64_t deadline) {
int err = 0;
if(dill_slow(!name || port <= 0)) {err = EINVAL; goto exit1;}
int chconns[2];
int rc = dill_chmake(chconns);
struct dill_chstorage chconns_storage;
int rc = dill_chmake_mem(&chconns_storage, chconns);
if(dill_slow(rc < 0)) {err = errno; goto exit1;}
int bndl = dill_bundle();
if(dill_slow(bndl < 0)) {err = errno; goto exit2;}
rc = dill_bundle_go(bndl, dill_happyeyeballs_coordinator(name, port,
chconns[1]));
if(dill_slow(rc < 0)) {err = errno; goto exit3;}
int coord = dill_go(dill_happyeyeballs_coordinator(name, port, chconns[1]));
if(dill_slow(coord < 0)) {err = errno; goto exit2;}
int conn;
rc = dill_chrecv(chconns[0], &conn, sizeof(int), deadline);
if(dill_slow(rc < 0)) {err = errno; goto exit3;}
res = conn;
exit3:
rc = dill_hclose(bndl);
rc = dill_hclose(coord);
dill_assert(rc == 0);
exit2:
rc = dill_hclose(chconns[0]);
Expand Down

0 comments on commit 16f0fcd

Please sign in to comment.