static void dyad_destroyStream(dyad_Stream *stream) { dyad_Event e; dyad_Stream **next; /* Close socket */ if (stream->sockfd != -1) { close(stream->sockfd); } /* Emit destroy event */ e = dyad_createEvent(DYAD_EVENT_DESTROY); e.msg = "the stream has been destroyed"; dyad_emitEvent(stream, &e); /* Remove from list and decrement count */ next = &dyad_streams; while (*next != stream) { next = &(*next)->next; } *next = stream->next; dyad_streamCount--; /* Destroy and free */ dyad_vectorDeinit(&stream->listeners); dyad_vectorDeinit(&stream->lineBuffer); dyad_vectorDeinit(&stream->writeBuffer); dyad_free(stream->address); dyad_free(stream); }
static void dyad_selectDeinit(dyad_SelectSet *s) { int i; for (i = 0; i < DYAD_SET_MAX; i++) { dyad_free(s->fds[i]); s->fds[i] = NULL; } s->capacity = 0; }
static void select_deinit(SelectSet *s) { int i; for (i = 0; i < SELECT_MAX; i++) { dyad_free(s->fds[i]); s->fds[i] = NULL; } s->capacity = 0; }
static void dyad_destroyStream(dyad_Stream *stream) { dyad_Stream **next; /* Close socket */ if (stream->sockfd != -1) { close(stream->sockfd); } /* Remove from list and decrement count */ next = &dyad_streams; while (*next != stream) { next = &(*next)->next; } *next = stream->next; dyad_streamCount--; /* Destroy and free */ dyad_vectorDeinit(&stream->listeners); dyad_vectorDeinit(&stream->lineBuffer); dyad_vectorDeinit(&stream->writeBuffer); dyad_free(stream->address); dyad_free(stream); }
static void dyad_initAddress(dyad_Stream *stream) { union { struct sockaddr sa; struct sockaddr_storage sas; struct sockaddr_in sai; struct sockaddr_in6 sai6; } addr; socklen_t size; memset(&addr, 0, sizeof(addr)); size = sizeof(addr); dyad_free(stream->address); if (getpeername(stream->sockfd, &addr.sa, &size) == -1) { return; } if (addr.sas.ss_family == AF_INET6) { stream->address = dyad_realloc(NULL, 46); inet_ntop(AF_INET6, &addr.sai6.sin6_addr, stream->address, 45); stream->port = ntohs(addr.sai6.sin6_port); } else { stream->address = dyad_realloc(NULL, 16); inet_ntop(AF_INET, &addr.sai.sin_addr, stream->address, 15); stream->port = ntohs(addr.sai.sin_port); } }