Пример #1
0
int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
    LPWSAPROTOCOL_INFOW protocol_info) {
  if (!(handle->flags & UV_HANDLE_CONNECTION)) {
    /*
     * We're about to share the socket with another process.  Because
     * this is a listening socket, we assume that the other process will
     * be accepting connections on it.  So, before sharing the socket
     * with another process, we call listen here in the parent process.
     */

    if (!(handle->flags & UV_HANDLE_LISTENING)) {
      if (!(handle->flags & UV_HANDLE_BOUND)) {
        return ERROR_INVALID_PARAMETER;
      }

      /* Report any deferred bind errors now. */
      if (handle->flags & UV_HANDLE_BIND_ERROR) {
        return handle->bind_error;
      }

      if (listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
        return WSAGetLastError();
      }
    }
  }

  if (WSADuplicateSocketW(handle->socket, pid, protocol_info)) {
    return WSAGetLastError();
  }

  handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET;

  return 0;
}
Пример #2
0
int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
    LPWSAPROTOCOL_INFOW protocol_info) {
  assert(!(handle->flags & UV_HANDLE_CONNECTION));

  /* 
   * We're about to share the socket with another process.  Because
   * this is a listening socket, we assume that the other process will
   * be accepting connections on it.  So, before sharing the socket
   * with another process, we call listen here in the parent process.
   * This needs to be modified if the socket is shared with
   * another process for anything other than accepting connections.
   */

  if (!(handle->flags & UV_HANDLE_LISTENING)) {
    if (!(handle->flags & UV_HANDLE_BOUND)) {
      uv__set_artificial_error(handle->loop, UV_EINVAL);
      return -1;
    }
    if (listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
      uv__set_sys_error(handle->loop, WSAGetLastError());
      return -1;
    }

    handle->flags |= UV_HANDLE_SHARED_TCP_SERVER;
  }

  if (WSADuplicateSocketW(handle->socket, pid, protocol_info)) {
    uv__set_sys_error(handle->loop, WSAGetLastError());
    return -1;
  }

  return 0;
}
Пример #3
0
int uv__tcp_xfer_export(uv_tcp_t* handle,
                        int target_pid,
                        uv__ipc_socket_xfer_type_t* xfer_type,
                        uv__ipc_socket_xfer_info_t* xfer_info) {
  if (handle->flags & UV_HANDLE_CONNECTION) {
    *xfer_type = UV__IPC_SOCKET_XFER_TCP_CONNECTION;
  } else {
    *xfer_type = UV__IPC_SOCKET_XFER_TCP_SERVER;
    /* We're about to share the socket with another process. Because this is a
     * listening socket, we assume that the other process will be accepting
     * connections on it. Thus, before sharing the socket with another process,
     * we call listen here in the parent process. */
    if (!(handle->flags & UV_HANDLE_LISTENING)) {
      if (!(handle->flags & UV_HANDLE_BOUND)) {
        return ERROR_NOT_SUPPORTED;
      }
      if (handle->delayed_error == 0 &&
          listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
        handle->delayed_error = WSAGetLastError();
      }
    }
  }

  if (WSADuplicateSocketW(handle->socket, target_pid, &xfer_info->socket_info))
    return WSAGetLastError();
  xfer_info->delayed_error = handle->delayed_error;

  /* Mark the local copy of the handle as 'shared' so we behave in a way that's
   * friendly to the process(es) that we share the socket with. */
  handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET;

  return 0;
}
Пример #4
0
/*
 * @unimplemented
 */
INT
EXPORT
WSADuplicateSocketA(IN  SOCKET s,
                    IN  DWORD dwProcessId,
                    OUT LPWSAPROTOCOL_INFOA lpProtocolInfo)
{
#if 0
    WSAPROTOCOL_INFOA ProtocolInfoU;

    Error  = WSADuplicateSocketW(s,
                               dwProcessId,
                               &ProtocolInfoU);

    if (Error == NO_ERROR)
    {
        UnicodeToAnsi(lpProtocolInfo,
                      ProtocolInfoU,
                      sizeof(

    }
Пример #5
0
/*
 * @implemented
 */
INT
WSAAPI
WSADuplicateSocketA(IN SOCKET s,
                    IN DWORD dwProcessId,
                    OUT LPWSAPROTOCOL_INFOA lpProtocolInfo)
{
    WSAPROTOCOL_INFOW ProtocolInfoW;
    INT ErrorCode;
    DPRINT("WSADuplicateSocketA: %lx, %lx, %p\n", s, dwProcessId, lpProtocolInfo);
  
    /* Call the Unicode Function */
    ErrorCode = WSADuplicateSocketW(s, dwProcessId, &ProtocolInfoW);

    /* Check for success */
    if (ErrorCode == ERROR_SUCCESS)
    {                          
        /* Convert Protocol Info to Ansi */
        if (lpProtocolInfo) 
        {    
            /* Convert the information to ANSI */
            ErrorCode = MapUnicodeProtocolInfoToAnsi(&ProtocolInfoW,
                                                     lpProtocolInfo);
        }
        else
        {
            /* Fail */
            ErrorCode = WSAEFAULT;
        }

        /* Check if the conversion failed */
        if (ErrorCode != ERROR_SUCCESS)
        {
            /* Set the last error and normalize the error */
            SetLastError(ErrorCode);
            ErrorCode = SOCKET_ERROR;
        }
    }

    /* Return */
    return ErrorCode;
}
Пример #6
0
static void socket_fork(struct file *f, HANDLE child_process, DWORD child_process_id)
{
	struct socket_file *socket_file = (struct socket_file *) f;
	AcquireSRWLockExclusive(&f->rw_lock);
	WSADuplicateSocketW(socket_file->socket, child_process_id, &socket_file->fork_info);
}