コード例 #1
0
void
psckt_close(psckt_t *sock)
{
  if (sock) {
    psckt_shutdown(sock);
    p_free(sock);
  } else {
    while (psckt_list) psckt_shutdown(psckt_list);
  }
}
コード例 #2
0
ファイル: wsock.c プロジェクト: dhmunro/yorick
void
psckt_close(psckt_t *sock)
{
  if (sock) {
    psckt_shutdown(sock);
    p_free(sock);
  } else {
    while (psckt_list) psckt_shutdown(psckt_list);
    if (psckt_initialized) WSACleanup();
  }
}
コード例 #3
0
ファイル: wsock.c プロジェクト: dhmunro/yorick
/* return value <0 for error, <len means socket recv side closed */
long
psckt_recv(psckt_t *sock, void *msg, long len)
{
  char *cmsg = msg;
  int n;
  if (len>0 && sock->callback && sock->waiting) {
    if (WaitForSingleObject(sock->ready, INFINITE) != WAIT_OBJECT_0)
      psckt_stop_thread(sock);
    sock->waiting = 0;
    if (sock->ready != INVALID_HANDLE_VALUE)
      ResetEvent(sock->ready);
  }
  while (len > 0) {
    n = recv(sock->fd, cmsg, len, 0);
    if (n < 0) return (long)psckt_shutdown(sock);
    if (n == 0) {  /* socket closed */
      /* socket may close for recv but not for send, not full shutdown yet
       * ...but remove from event sources and kill wait thread immediately
       */
      if (sock->callback) psckt_stop_thread(sock);
      break;
    }
    cmsg += n;
    len -= n;
  }
  return cmsg - (const char *)msg;
}
コード例 #4
0
int
psckt_send(psckt_t *sock, const void *msg, long len)
{
  const char *cmsg = msg;
  int n;
  while (len > 0) {
    n = send(sock->fd, cmsg, len, 0);
    if (n < 0) return psckt_shutdown(sock);
    cmsg += n;
    len -= n;
  }
  return 0;
}
コード例 #5
0
/* return value <0 for error, <len means socket recv side closed */
long
psckt_recv(psckt_t *sock, void *msg, long len)
{
  char *cmsg = msg;
  int n;
  while (len > 0) {
    n = recv(sock->fd, cmsg, len, 0);
    if (n < 0) return (psckt_shutdown(sock), -1L);
    if (n == 0) {  /* socket closed */
      /* socket may close for recv but not for send, not full shutdown yet */
      if (sock->callback) { /* ...but remove from event sources immediately */
        sock->callback = 0; 
        u_event_src(sock->fd, 0, sock);
      }
      break;
    }
    cmsg += n;
    len -= n;
  }
  return cmsg - (const char *)msg;
}