您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ uv_translate_sys_error函数代码示例

51自学网 2021-06-03 09:28:29
  C++
这篇教程C++ uv_translate_sys_error函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中uv_translate_sys_error函数的典型用法代码示例。如果您正苦于以下问题:C++ uv_translate_sys_error函数的具体用法?C++ uv_translate_sys_error怎么用?C++ uv_translate_sys_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了uv_translate_sys_error函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: uv_if_indextoiid

int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) {  int r;  if (buffer == NULL || size == NULL || *size == 0)    return UV_EINVAL;  r = snprintf(buffer, *size, "%d", ifindex);  if (r < 0)    return uv_translate_sys_error(r);  if (r >= (int) *size) {    *size = r + 1;    return UV_ENOBUFS;  }  *size = r;  return 0;}
开发者ID:AlexanderPankiv,项目名称:node,代码行数:19,


示例2: uv_get_process_title

int uv_get_process_title(char* buffer, size_t size) {    uv__once_init();    EnterCriticalSection(&process_title_lock);    /*     * If the process_title was never read before nor explicitly set,     * we must query it with getConsoleTitleW     */    if (!process_title && uv__get_process_title() == -1) {        LeaveCriticalSection(&process_title_lock);        return uv_translate_sys_error(GetLastError());    }    assert(process_title);    strncpy(buffer, process_title, size);    LeaveCriticalSection(&process_title_lock);    return 0;}
开发者ID:kjthegod,项目名称:node,代码行数:19,


示例3: uv_kill

int uv_kill(int pid, int signum) {  int err;  HANDLE process_handle = OpenProcess(PROCESS_TERMINATE |    PROCESS_QUERY_INFORMATION, FALSE, pid);  if (process_handle == NULL) {    err = GetLastError();    if (err == ERROR_INVALID_PARAMETER) {      return UV_ESRCH;    } else {      return uv_translate_sys_error(err);    }  }  err = uv__kill(process_handle, signum);  CloseHandle(process_handle);  return err;  /* err is already translated. */}
开发者ID:BenKoerber,项目名称:clearskies_core,代码行数:19,


示例4: uv_read_stop

int uv_read_stop(uv_stream_t* handle) {  int err;  if (!(handle->flags & UV_HANDLE_READING))    return 0;  err = 0;  if (handle->type == UV_TTY) {    err = uv_tty_read_stop((uv_tty_t*) handle);  } else {    if (handle->type == UV_NAMED_PIPE) {      uv__pipe_stop_read((uv_pipe_t*) handle);    } else {      handle->flags &= ~UV_HANDLE_READING;    }    DECREASE_ACTIVE_COUNT(handle->loop, handle);  }  return uv_translate_sys_error(err);}
开发者ID:Muraad,项目名称:harmony,代码行数:20,


示例5: uv__fs_done

static void uv__fs_done(struct uv__work* w, int status) {  uv_fs_t* req;  req = container_of(w, uv_fs_t, work_req);  uv__req_unregister(req->loop, req);  if (req->errorno != 0) {    req->errorno = uv_translate_sys_error(req->errorno);    uv__set_artificial_error(req->loop, req->errorno);  }  if (status == -UV_ECANCELED) {    assert(req->errorno == 0);    req->errorno = UV_ECANCELED;    uv__set_artificial_error(req->loop, UV_ECANCELED);  }  if (req->cb != NULL)    req->cb(req);}
开发者ID:76765357,项目名称:node,代码行数:20,


示例6: uv__slow_poll_process_poll_req

static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,    uv_req_t* req) {  unsigned char mask_events;  int err;  if (req == &handle->poll_req_1) {    handle->submitted_events_1 = 0;    mask_events = handle->mask_events_1;  } else if (req == &handle->poll_req_2) {    handle->submitted_events_2 = 0;    mask_events = handle->mask_events_2;  } else {    assert(0);    return;  }  if (!REQ_SUCCESS(req)) {    /* Error. */    if (handle->events != 0) {      err = GET_REQ_ERROR(req);      handle->events = 0; /* Stop the watcher */      handle->poll_cb(handle, uv_translate_sys_error(err), 0);    }  } else {    /* Got some events. */    int events = req->u.io.overlapped.InternalHigh & handle->events & ~mask_events;    if (events != 0) {      handle->poll_cb(handle, 0, events);    }  }  if ((handle->events & ~(handle->submitted_events_1 |      handle->submitted_events_2)) != 0) {    uv__slow_poll_submit_poll_req(loop, handle);  } else if ((handle->flags & UV__HANDLE_CLOSING) &&             handle->submitted_events_1 == 0 &&             handle->submitted_events_2 == 0) {    uv_want_endgame(loop, (uv_handle_t*) handle);  }}
开发者ID:125radheyshyam,项目名称:node,代码行数:40,


示例7: uv__tcp_try_write

int uv__tcp_try_write(uv_tcp_t* handle,                     const uv_buf_t bufs[],                     unsigned int nbufs) {  int result;  DWORD bytes;  if (handle->stream.conn.write_reqs_pending > 0)    return UV_EAGAIN;  result = WSASend(handle->socket,                   (WSABUF*) bufs,                   nbufs,                   &bytes,                   0,                   NULL,                   NULL);  if (result == SOCKET_ERROR)    return uv_translate_sys_error(WSAGetLastError());  else    return bytes;}
开发者ID:AlexanderPankiv,项目名称:node,代码行数:22,


示例8: uv_process_tcp_write_req

void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,    uv_write_t* req) {  int err;  assert(handle->type == UV_TCP);  assert(handle->write_queue_size >= req->u.io.queued_bytes);  handle->write_queue_size -= req->u.io.queued_bytes;  UNREGISTER_HANDLE_REQ(loop, handle, req);  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {    if (req->wait_handle != INVALID_HANDLE_VALUE) {      UnregisterWait(req->wait_handle);      req->wait_handle = INVALID_HANDLE_VALUE;    }    if (req->event_handle) {      CloseHandle(req->event_handle);      req->event_handle = NULL;    }  }  if (req->cb) {    err = uv_translate_sys_error(GET_REQ_SOCK_ERROR(req));    if (err == UV_ECONNABORTED) {      /* use UV_ECANCELED for consistency with Unix */      err = UV_ECANCELED;    }    req->cb(req, err);  }  handle->stream.conn.write_reqs_pending--;  if (handle->stream.conn.shutdown_req != NULL &&      handle->stream.conn.write_reqs_pending == 0) {    uv_want_endgame(loop, (uv_handle_t*)handle);  }  DECREASE_PENDING_REQ_COUNT(handle);}
开发者ID:AlexanderPankiv,项目名称:node,代码行数:39,


示例9: uv_getnameinfo

/** Entry point for getnameinfo* return 0 if a callback will be made* return error code if validation fails*/int uv_getnameinfo(uv_loop_t* loop,                   uv_getnameinfo_t* req,                   uv_getnameinfo_cb getnameinfo_cb,                   const struct sockaddr* addr,                   int flags) {  if (req == NULL || getnameinfo_cb == NULL || addr == NULL)    return UV_EINVAL;  if (addr->sa_family == AF_INET) {    memcpy(&req->storage,           addr,           sizeof(struct sockaddr_in));  } else if (addr->sa_family == AF_INET6) {    memcpy(&req->storage,           addr,           sizeof(struct sockaddr_in6));  } else {    return UV_EINVAL;  }  uv_req_init(loop, (uv_req_t*)req);  req->getnameinfo_cb = getnameinfo_cb;  req->flags = flags;  req->type = UV_GETNAMEINFO;  req->loop = loop;  /* Ask thread to run. Treat this as a long operation. */  if (QueueUserWorkItem(&getnameinfo_thread_proc,                        req,                        WT_EXECUTELONGFUNCTION) == 0) {    return uv_translate_sys_error(GetLastError());  }  uv__req_register(loop, req);  return 0;}
开发者ID:7designstudios,项目名称:node,代码行数:43,


示例10: uv_read2_start

int uv_read2_start(uv_stream_t* handle, uv_alloc_cb alloc_cb,    uv_read2_cb read_cb) {  int err;  if (handle->flags & UV_HANDLE_READING) {    return UV_EALREADY;  }  if (!(handle->flags & UV_HANDLE_READABLE)) {    return UV_ENOTCONN;  }  err = ERROR_INVALID_PARAMETER;  switch (handle->type) {    case UV_NAMED_PIPE:      err = uv_pipe_read2_start((uv_pipe_t*)handle, alloc_cb, read_cb);      break;    default:      assert(0);  }  return uv_translate_sys_error(err);}
开发者ID:Durai,项目名称:node,代码行数:23,


示例11: uv_process_udp_send_req

void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,    uv_udp_send_t* req) {  int err;  assert(handle->type == UV_UDP);  assert(handle->send_queue_size >= req->u.io.queued_bytes);  assert(handle->send_queue_count >= 1);  handle->send_queue_size -= req->u.io.queued_bytes;  handle->send_queue_count--;  UNREGISTER_HANDLE_REQ(loop, handle, req);  if (req->cb) {    err = 0;    if (!REQ_SUCCESS(req)) {      err = GET_REQ_SOCK_ERROR(req);    }    req->cb(req, uv_translate_sys_error(err));  }  DECREASE_PENDING_REQ_COUNT(handle);}
开发者ID:ajafff,项目名称:node,代码行数:23,


示例12: uv_process_proc_exit

/* Called on main thread after a child process has exited. */void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) {  int64_t exit_code;  DWORD status;  assert(handle->exit_cb_pending);  handle->exit_cb_pending = 0;  /* If we're closing, don't call the exit callback. Just schedule a close */  /* callback now. */  if (handle->flags & UV__HANDLE_CLOSING) {    uv_want_endgame(loop, (uv_handle_t*) handle);    return;  }  /* Unregister from process notification. */  if (handle->wait_handle != INVALID_HANDLE_VALUE) {    UnregisterWait(handle->wait_handle);    handle->wait_handle = INVALID_HANDLE_VALUE;  }  /* Set the handle to inactive: no callbacks will be made after the exit */  /* callback.*/  uv__handle_stop(handle);  if (GetExitCodeProcess(handle->process_handle, &status)) {    exit_code = status;  } else {    /* Unable to to obtain the exit code. This should never happen. */    exit_code = uv_translate_sys_error(GetLastError());  }  /* Fire the exit callback. */  if (handle->exit_cb) {    handle->exit_cb(handle, exit_code, handle->exit_signal);  }}
开发者ID:BenKoerber,项目名称:clearskies_core,代码行数:37,


示例13: uv_cond_fallback_init

inline static int uv_cond_fallback_init(uv_cond_t* cond) {  int err;  /* Initialize the count to 0. */  cond->fallback.waiters_count = 0;  InitializeCriticalSection(&cond->fallback.waiters_count_lock);  /* Create an auto-reset event. */  cond->fallback.signal_event = CreateEvent(NULL,  /* no security */                                            FALSE, /* auto-reset event */                                            FALSE, /* non-signaled initially */                                            NULL); /* unnamed */  if (!cond->fallback.signal_event) {    err = GetLastError();    goto error2;  }  /* Create a manual-reset event. */  cond->fallback.broadcast_event = CreateEvent(NULL,  /* no security */                                               TRUE,  /* manual-reset */                                               FALSE, /* non-signaled */                                               NULL); /* unnamed */  if (!cond->fallback.broadcast_event) {    err = GetLastError();    goto error;  }  return 0;error:  CloseHandle(cond->fallback.signal_event);error2:  DeleteCriticalSection(&cond->fallback.waiters_count_lock);  return uv_translate_sys_error(err);}
开发者ID:0x20c24,项目名称:cjdns,代码行数:36,


示例14: uv_cpu_info

//.........这里部分代码省略.........    r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,                      key_name,                      0,                      KEY_QUERY_VALUE,                      &processor_key);    if (r != ERROR_SUCCESS) {      err = GetLastError();      goto error;    }    if (RegQueryValueExW(processor_key,                         L"~MHz",                         NULL,                         NULL,                         (BYTE*) &cpu_speed,                         &cpu_speed_size) != ERROR_SUCCESS) {      err = GetLastError();      RegCloseKey(processor_key);      goto error;    }    if (RegQueryValueExW(processor_key,                         L"ProcessorNameString",                         NULL,                         NULL,                         (BYTE*) &cpu_brand,                         &cpu_brand_size) != ERROR_SUCCESS) {      err = GetLastError();      RegCloseKey(processor_key);      goto error;    }    RegCloseKey(processor_key);    cpu_info = &cpu_infos[i];    cpu_info->speed = cpu_speed;    cpu_info->cpu_times.user = sppi[i].UserTime.QuadPart / 10000;    cpu_info->cpu_times.sys = (sppi[i].KernelTime.QuadPart -        sppi[i].IdleTime.QuadPart) / 10000;    cpu_info->cpu_times.idle = sppi[i].IdleTime.QuadPart / 10000;    cpu_info->cpu_times.irq = sppi[i].InterruptTime.QuadPart / 10000;    cpu_info->cpu_times.nice = 0;    len = WideCharToMultiByte(CP_UTF8,                              0,                              cpu_brand,                              cpu_brand_size / sizeof(WCHAR),                              NULL,                              0,                              NULL,                              NULL);    if (len == 0) {      err = GetLastError();      goto error;    }    assert(len > 0);    /* Allocate 1 extra byte for the null terminator. */    cpu_info->model = malloc(len + 1);    if (cpu_info->model == NULL) {      err = ERROR_OUTOFMEMORY;      goto error;    }    if (WideCharToMultiByte(CP_UTF8,                            0,                            cpu_brand,                            cpu_brand_size / sizeof(WCHAR),                            cpu_info->model,                            len,                            NULL,                            NULL) == 0) {      err = GetLastError();      goto error;    }    /* Ensure that cpu_info->model is null terminated. */    cpu_info->model[len] = '/0';  }  free(sppi);  *cpu_count_ptr = cpu_count;  *cpu_infos_ptr = cpu_infos;  return 0; error:  /* This is safe because the cpu_infos array is zeroed on allocation. */  for (i = 0; i < cpu_count; i++)    free(cpu_infos[i].model);  free(cpu_infos);  free(sppi);  return uv_translate_sys_error(err);}
开发者ID:5y,项目名称:node,代码行数:101,


示例15: uv_interface_addresses

int uv_interface_addresses(uv_interface_address_t** addresses_ptr,    int* count_ptr) {  IP_ADAPTER_ADDRESSES* win_address_buf;  ULONG win_address_buf_size;  IP_ADAPTER_ADDRESSES* adapter;  uv_interface_address_t* uv_address_buf;  char* name_buf;  size_t uv_address_buf_size;  uv_interface_address_t* uv_address;  int count;  int is_vista_or_greater;  ULONG flags;  is_vista_or_greater = is_windows_version_or_greater(6, 0, 0, 0);  if (is_vista_or_greater) {    flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |      GAA_FLAG_SKIP_DNS_SERVER;  } else {    /* We need at least XP SP1. */    if (!is_windows_version_or_greater(5, 1, 1, 0))      return UV_ENOTSUP;    flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |      GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_INCLUDE_PREFIX;  }    /* Fetch the size of the adapters reported by windows, and then get the */  /* list itself. */  win_address_buf_size = 0;  win_address_buf = NULL;  for (;;) {    ULONG r;    /* If win_address_buf is 0, then GetAdaptersAddresses will fail with */    /* ERROR_BUFFER_OVERFLOW, and the required buffer size will be stored in */    /* win_address_buf_size. */    r = GetAdaptersAddresses(AF_UNSPEC,                             flags,                             NULL,                             win_address_buf,                             &win_address_buf_size);    if (r == ERROR_SUCCESS)      break;    free(win_address_buf);    switch (r) {      case ERROR_BUFFER_OVERFLOW:        /* This happens when win_address_buf is NULL or too small to hold */        /* all adapters. */        win_address_buf = malloc(win_address_buf_size);        if (win_address_buf == NULL)          return UV_ENOMEM;        continue;      case ERROR_NO_DATA: {        /* No adapters were found. */        uv_address_buf = malloc(1);        if (uv_address_buf == NULL)          return UV_ENOMEM;        *count_ptr = 0;        *addresses_ptr = uv_address_buf;        return 0;      }      case ERROR_ADDRESS_NOT_ASSOCIATED:        return UV_EAGAIN;      case ERROR_INVALID_PARAMETER:        /* MSDN says:         *   "This error is returned for any of the following conditions: the         *   SizePointer parameter is NULL, the Address parameter is not         *   AF_INET, AF_INET6, or AF_UNSPEC, or the address information for         *   the parameters requested is greater than ULONG_MAX."         * Since the first two conditions are not met, it must be that the         * adapter data is too big.         */        return UV_ENOBUFS;      default:        /* Other (unspecified) errors can happen, but we don't have any */        /* special meaning for them. */        assert(r != ERROR_SUCCESS);        return uv_translate_sys_error(r);    }  }  /* Count the number of enabled interfaces and compute how much space is */  /* needed to store their info. */  count = 0;  uv_address_buf_size = 0;//.........这里部分代码省略.........
开发者ID:5y,项目名称:node,代码行数:101,


示例16: uv_chdir

int uv_chdir(const char* dir) {  WCHAR utf16_buffer[MAX_PATH];  size_t utf16_len;  WCHAR drive_letter, env_var[4];  if (dir == NULL) {    return UV_EINVAL;  }  if (MultiByteToWideChar(CP_UTF8,                          0,                          dir,                          -1,                          utf16_buffer,                          MAX_PATH) == 0) {    DWORD error = GetLastError();    /* The maximum length of the current working directory is 260 chars, */    /* including terminating null. If it doesn't fit, the path name must be */    /* too long. */    if (error == ERROR_INSUFFICIENT_BUFFER) {      return UV_ENAMETOOLONG;    } else {      return uv_translate_sys_error(error);    }  }  if (!SetCurrentDirectoryW(utf16_buffer)) {    return uv_translate_sys_error(GetLastError());  }  /* Windows stores the drive-local path in an "hidden" environment variable, */  /* which has the form "=C:=C:/Windows". SetCurrentDirectory does not */  /* update this, so we'll have to do it. */  utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);  if (utf16_len == 0) {    return uv_translate_sys_error(GetLastError());  } else if (utf16_len > MAX_PATH) {    return UV_EIO;  }  /* The returned directory should not have a trailing slash, unless it */  /* points at a drive root, like c:/. Remove it if needed. */  if (utf16_buffer[utf16_len - 1] == L'//' &&      !(utf16_len == 3 && utf16_buffer[1] == L':')) {    utf16_len--;    utf16_buffer[utf16_len] = L'/0';  }  if (utf16_len < 2 || utf16_buffer[1] != L':') {    /* Doesn't look like a drive letter could be there - probably an UNC */    /* path. TODO: Need to handle win32 namespaces like //?/C:/ ? */    drive_letter = 0;  } else if (utf16_buffer[0] >= L'A' && utf16_buffer[0] <= L'Z') {    drive_letter = utf16_buffer[0];  } else if (utf16_buffer[0] >= L'a' && utf16_buffer[0] <= L'z') {    /* Convert to uppercase. */    drive_letter = utf16_buffer[0] - L'a' + L'A';  } else {    /* Not valid. */    drive_letter = 0;  }  if (drive_letter != 0) {    /* Construct the environment variable name and set it. */    env_var[0] = L'=';    env_var[1] = drive_letter;    env_var[2] = L':';    env_var[3] = L'/0';    if (!SetEnvironmentVariableW(env_var, utf16_buffer)) {      return uv_translate_sys_error(GetLastError());    }  }  return 0;}
开发者ID:5y,项目名称:node,代码行数:76,


示例17: uv_uptime

int uv_uptime(double* uptime) {  BYTE stack_buffer[4096];  BYTE* malloced_buffer = NULL;  BYTE* buffer = (BYTE*) stack_buffer;  size_t buffer_size = sizeof(stack_buffer);  DWORD data_size;  PERF_DATA_BLOCK* data_block;  PERF_OBJECT_TYPE* object_type;  PERF_COUNTER_DEFINITION* counter_definition;  DWORD i;  for (;;) {    LONG result;    data_size = (DWORD) buffer_size;    result = RegQueryValueExW(HKEY_PERFORMANCE_DATA,                              L"2",                              NULL,                              NULL,                              buffer,                              &data_size);    if (result == ERROR_SUCCESS) {      break;    } else if (result != ERROR_MORE_DATA) {      *uptime = 0;      return uv_translate_sys_error(result);    }    buffer_size *= 2;    /* Don't let the buffer grow infinitely. */    if (buffer_size > 1 << 20) {      goto internalError;    }    free(malloced_buffer);    buffer = malloced_buffer = (BYTE*) malloc(buffer_size);    if (malloced_buffer == NULL) {      *uptime = 0;      return UV_ENOMEM;    }  }  if (data_size < sizeof(*data_block))    goto internalError;  data_block = (PERF_DATA_BLOCK*) buffer;  if (wmemcmp(data_block->Signature, L"PERF", 4) != 0)    goto internalError;  if (data_size < data_block->HeaderLength + sizeof(*object_type))    goto internalError;  object_type = (PERF_OBJECT_TYPE*) (buffer + data_block->HeaderLength);  if (object_type->NumInstances != PERF_NO_INSTANCES)    goto internalError;  counter_definition = (PERF_COUNTER_DEFINITION*) (buffer +      data_block->HeaderLength + object_type->HeaderLength);  for (i = 0; i < object_type->NumCounters; i++) {    if ((BYTE*) counter_definition + sizeof(*counter_definition) >        buffer + data_size) {      break;    }    if (counter_definition->CounterNameTitleIndex == 674 &&        counter_definition->CounterSize == sizeof(uint64_t)) {      if (counter_definition->CounterOffset + sizeof(uint64_t) > data_size ||          !(counter_definition->CounterType & PERF_OBJECT_TIMER)) {        goto internalError;      } else {        BYTE* address = (BYTE*) object_type + object_type->DefinitionLength +                        counter_definition->CounterOffset;        uint64_t value = *((uint64_t*) address);        *uptime = (double) (object_type->PerfTime.QuadPart - value) /                  (double) object_type->PerfFreq.QuadPart;        free(malloced_buffer);        return 0;      }    }    counter_definition = (PERF_COUNTER_DEFINITION*)        ((BYTE*) counter_definition + counter_definition->ByteLength);  }  /* If we get here, the uptime value was not found. */  free(malloced_buffer);  *uptime = 0;  return UV_ENOSYS; internalError:  free(malloced_buffer);  *uptime = 0;  return UV_EIO;}
开发者ID:5y,项目名称:node,代码行数:99,


示例18: uv_process_tcp_read_req

void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,    uv_req_t* req) {  DWORD bytes, flags, err;  uv_buf_t buf;  assert(handle->type == UV_TCP);  handle->flags &= ~UV_HANDLE_READ_PENDING;  if (!REQ_SUCCESS(req)) {    /* An error occurred doing the read. */    if ((handle->flags & UV_HANDLE_READING) ||        !(handle->flags & UV_HANDLE_ZERO_READ)) {      handle->flags &= ~UV_HANDLE_READING;      DECREASE_ACTIVE_COUNT(loop, handle);      buf = (handle->flags & UV_HANDLE_ZERO_READ) ?            uv_buf_init(NULL, 0) : handle->read_buffer;      err = GET_REQ_SOCK_ERROR(req);      if (err == WSAECONNABORTED) {        /*         * Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix.         */        err = WSAECONNRESET;      }      handle->read_cb((uv_stream_t*)handle,                      uv_translate_sys_error(err),                      &buf);    }  } else {    if (!(handle->flags & UV_HANDLE_ZERO_READ)) {      /* The read was done with a non-zero buffer length. */      if (req->overlapped.InternalHigh > 0) {        /* Successful read */        handle->read_cb((uv_stream_t*)handle,                        req->overlapped.InternalHigh,                        &handle->read_buffer);        /* Read again only if bytes == buf.len */        if (req->overlapped.InternalHigh < handle->read_buffer.len) {          goto done;        }      } else {        /* Connection closed */        if (handle->flags & UV_HANDLE_READING) {          handle->flags &= ~UV_HANDLE_READING;          DECREASE_ACTIVE_COUNT(loop, handle);        }        handle->flags &= ~UV_HANDLE_READABLE;        buf.base = 0;        buf.len = 0;        handle->read_cb((uv_stream_t*)handle, UV_EOF, &handle->read_buffer);        goto done;      }    }    /* Do nonblocking reads until the buffer is empty */    while (handle->flags & UV_HANDLE_READING) {      handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);      if (buf.len == 0) {        handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);        break;      }      assert(buf.base != NULL);      flags = 0;      if (WSARecv(handle->socket,                  (WSABUF*)&buf,                  1,                  &bytes,                  &flags,                  NULL,                  NULL) != SOCKET_ERROR) {        if (bytes > 0) {          /* Successful read */          handle->read_cb((uv_stream_t*)handle, bytes, &buf);          /* Read again only if bytes == buf.len */          if (bytes < buf.len) {            break;          }        } else {          /* Connection closed */          handle->flags &= ~(UV_HANDLE_READING | UV_HANDLE_READABLE);          DECREASE_ACTIVE_COUNT(loop, handle);          handle->read_cb((uv_stream_t*)handle, UV_EOF, &buf);          break;        }      } else {        err = WSAGetLastError();        if (err == WSAEWOULDBLOCK) {          /* Read buffer was completely empty, report a 0-byte read. */          handle->read_cb((uv_stream_t*)handle, 0, &buf);        } else {          /* Ouch! serious error. */          handle->flags &= ~UV_HANDLE_READING;          DECREASE_ACTIVE_COUNT(loop, handle);//.........这里部分代码省略.........
开发者ID:flybird119,项目名称:libuv-vc6,代码行数:101,


示例19: uv_cwd

int uv_cwd(char* buffer, size_t* size) {  DWORD utf16_len;  WCHAR utf16_buffer[MAX_PATH];  int r;  if (buffer == NULL || size == NULL) {    return UV_EINVAL;  }  utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);  if (utf16_len == 0) {    return uv_translate_sys_error(GetLastError());  } else if (utf16_len > MAX_PATH) {    /* This should be impossible;  however the CRT has a code path to deal */    /* with this scenario, so I added a check anyway. */    return UV_EIO;  }  /* utf16_len contains the length, *not* including the terminating null. */  utf16_buffer[utf16_len] = L'/0';  /* The returned directory should not have a trailing slash, unless it */  /* points at a drive root, like c:/. Remove it if needed.*/  if (utf16_buffer[utf16_len - 1] == L'//' &&      !(utf16_len == 3 && utf16_buffer[1] == L':')) {    utf16_len--;    utf16_buffer[utf16_len] = L'/0';  }  /* Check how much space we need */  r = WideCharToMultiByte(CP_UTF8,                          0,                          utf16_buffer,                          -1,                          NULL,                          0,                          NULL,                          NULL);  if (r == 0) {    return uv_translate_sys_error(GetLastError());  } else if (r > (int) *size) {    *size = r -1;    return UV_ENOBUFS;  }  /* Convert to UTF-8 */  r = WideCharToMultiByte(CP_UTF8,                          0,                          utf16_buffer,                          -1,                          buffer,                          *size > INT_MAX ? INT_MAX : (int) *size,                          NULL,                          NULL);  if (r == 0) {    return uv_translate_sys_error(GetLastError());  }  *size = r - 1;  return 0;}
开发者ID:5y,项目名称:node,代码行数:61,


示例20: uv_process_fs_event_req

//.........这里部分代码省略.........                /* Get the file name out of the long path. */                result = uv_relative_path(long_filenamew,                                          handle->dirw,                                          &filenamew);                uv__free(long_filenamew);                if (result == 0) {                  long_filenamew = filenamew;                  sizew = -1;                } else {                  long_filenamew = NULL;                }              }              /*               * We could not resolve the long form explicitly.               * We therefore use the name given by ReadDirectoryChangesW.               * This may be the long form or the 8.3 short name in some cases.               */              if (!long_filenamew) {                filenamew = file_info->FileName;                sizew = file_info->FileNameLength / sizeof(WCHAR);              }            } else {              /*               * Removed or renamed events cannot be resolved to the long form.               * We therefore use the name given by ReadDirectoryChangesW.               * This may be the long form or the 8.3 short name in some cases.               */              if (!long_filenamew) {                filenamew = file_info->FileName;                sizew = file_info->FileNameLength / sizeof(WCHAR);              }            }          } else {            /* We already have the long name of the file, so just use it. */            filenamew = handle->filew;            sizew = -1;          }          if (filenamew) {            /* Convert the filename to utf8. */            size = uv_utf16_to_utf8(filenamew,                                    sizew,                                    NULL,                                    0);            if (size) {              filename = (char*)uv__malloc(size + 1);              if (!filename) {                uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");              }              size = uv_utf16_to_utf8(filenamew,                                      sizew,                                      filename,                                      size);              if (size) {                filename[size] = '/0';              } else {                uv__free(filename);                filename = NULL;              }            }          }          switch (file_info->Action) {            case FILE_ACTION_ADDED:            case FILE_ACTION_REMOVED:            case FILE_ACTION_RENAMED_OLD_NAME:            case FILE_ACTION_RENAMED_NEW_NAME:              handle->cb(handle, filename, UV_RENAME, 0);              break;            case FILE_ACTION_MODIFIED:              handle->cb(handle, filename, UV_CHANGE, 0);              break;          }          uv__free(filename);          filename = NULL;          uv__free(long_filenamew);          long_filenamew = NULL;        }        offset = file_info->NextEntryOffset;      } while (offset && !(handle->flags & UV__HANDLE_CLOSING));    } else {      handle->cb(handle, NULL, UV_CHANGE, 0);    }  } else {    err = GET_REQ_ERROR(req);    handle->cb(handle, NULL, 0, uv_translate_sys_error(err));  }  if (!(handle->flags & UV__HANDLE_CLOSING)) {    uv_fs_event_queue_readdirchanges(loop, handle);  } else {    uv_want_endgame(loop, (uv_handle_t*)handle);  }}
开发者ID:ComputerVisionWorks,项目名称:libsourcey,代码行数:101,


示例21: uv__getaddrinfo_done

/* * Called from uv_run when complete. Call user specified callback * then free returned addrinfo * Returned addrinfo strings are converted from UTF-16 to UTF-8. * * To minimize allocation we calculate total size required, * and copy all structs and referenced strings into the one block. * Each size calculation is adjusted to avoid unaligned pointers. */static void uv__getaddrinfo_done(struct uv__work* w, int status) {  uv_getaddrinfo_t* req;  int addrinfo_len = 0;  int name_len = 0;  size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo));  struct addrinfoW* addrinfow_ptr;  struct addrinfo* addrinfo_ptr;  char* alloc_ptr = NULL;  char* cur_ptr = NULL;  req = container_of(w, uv_getaddrinfo_t, work_req);  /* release input parameter memory */  if (req->alloc != NULL) {    free(req->alloc);    req->alloc = NULL;  }  if (status == UV_ECANCELED) {    assert(req->retcode == 0);    req->retcode = UV_EAI_CANCELED;    if (req->res != NULL) {        FreeAddrInfoW(req->res);        req->res = NULL;    }    goto complete;  }  if (req->retcode == 0) {    /* convert addrinfoW to addrinfo */    /* first calculate required length */    addrinfow_ptr = req->res;    while (addrinfow_ptr != NULL) {      addrinfo_len += addrinfo_struct_len +          ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);      if (addrinfow_ptr->ai_canonname != NULL) {        name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0);        if (name_len == 0) {          req->retcode = uv_translate_sys_error(GetLastError());          goto complete;        }        addrinfo_len += ALIGNED_SIZE(name_len);      }      addrinfow_ptr = addrinfow_ptr->ai_next;    }    /* allocate memory for addrinfo results */    alloc_ptr = (char*)malloc(addrinfo_len);    /* do conversions */    if (alloc_ptr != NULL) {      cur_ptr = alloc_ptr;      addrinfow_ptr = req->res;      while (addrinfow_ptr != NULL) {        /* copy addrinfo struct data */        assert(cur_ptr + addrinfo_struct_len <= alloc_ptr + addrinfo_len);        addrinfo_ptr = (struct addrinfo*)cur_ptr;        addrinfo_ptr->ai_family = addrinfow_ptr->ai_family;        addrinfo_ptr->ai_socktype = addrinfow_ptr->ai_socktype;        addrinfo_ptr->ai_protocol = addrinfow_ptr->ai_protocol;        addrinfo_ptr->ai_flags = addrinfow_ptr->ai_flags;        addrinfo_ptr->ai_addrlen = addrinfow_ptr->ai_addrlen;        addrinfo_ptr->ai_canonname = NULL;        addrinfo_ptr->ai_addr = NULL;        addrinfo_ptr->ai_next = NULL;        cur_ptr += addrinfo_struct_len;        /* copy sockaddr */        if (addrinfo_ptr->ai_addrlen > 0) {          assert(cur_ptr + addrinfo_ptr->ai_addrlen <=                 alloc_ptr + addrinfo_len);          memcpy(cur_ptr, addrinfow_ptr->ai_addr, addrinfo_ptr->ai_addrlen);          addrinfo_ptr->ai_addr = (struct sockaddr*)cur_ptr;          cur_ptr += ALIGNED_SIZE(addrinfo_ptr->ai_addrlen);        }        /* convert canonical name to UTF-8 */        if (addrinfow_ptr->ai_canonname != NULL) {          name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname,                                      -1,                                      NULL,                                      0);          assert(name_len > 0);          assert(cur_ptr + name_len <= alloc_ptr + addrinfo_len);          name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname,                                      -1,                                      cur_ptr,                                      name_len);          assert(name_len > 0);//.........这里部分代码省略.........
开发者ID:353355756,项目名称:node,代码行数:101,


示例22: uv__new_sys_error

uv_err_t uv__new_sys_error(int sys_error) {  uv_err_t error;  error.code = uv_translate_sys_error(sys_error);  error.sys_errno_ = sys_error;  return error;}
开发者ID:Laner,项目名称:gitbin,代码行数:6,


示例23: uv_fs_event_start

int uv_fs_event_start(uv_fs_event_t* handle,                      uv_fs_event_cb cb,                      const char* path,                      unsigned int flags) {  int name_size, is_path_dir;  DWORD attr, last_error;  WCHAR* dir = NULL, *dir_to_watch, *pathw = NULL;  WCHAR short_path[MAX_PATH];  if (uv__is_active(handle))    return UV_EINVAL;  handle->cb = cb;  handle->path = uv__strdup(path);  if (!handle->path) {    uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");  }  uv__handle_start(handle);  /* Convert name to UTF16. */  name_size = uv_utf8_to_utf16(path, NULL, 0) * sizeof(WCHAR);  pathw = (WCHAR*)uv__malloc(name_size);  if (!pathw) {    uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");  }  if (!uv_utf8_to_utf16(path, pathw,      name_size / sizeof(WCHAR))) {    return uv_translate_sys_error(GetLastError());  }  /* Determine whether path is a file or a directory. */  attr = GetFileAttributesW(pathw);  if (attr == INVALID_FILE_ATTRIBUTES) {    last_error = GetLastError();    goto error;  }  is_path_dir = (attr & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;  if (is_path_dir) {     /* path is a directory, so that's the directory that we will watch. */    handle->dirw = pathw;    dir_to_watch = pathw;  } else {    /*     * path is a file.  So we split path into dir & file parts, and     * watch the dir directory.     */    /* Convert to short path. */    if (!GetShortPathNameW(pathw, short_path, ARRAY_SIZE(short_path))) {      last_error = GetLastError();      goto error;    }    if (uv_split_path(pathw, &dir, &handle->filew) != 0) {      last_error = GetLastError();      goto error;    }    if (uv_split_path(short_path, NULL, &handle->short_filew) != 0) {      last_error = GetLastError();      goto error;    }    dir_to_watch = dir;    uv__free(pathw);    pathw = NULL;  }  handle->dir_handle = CreateFileW(dir_to_watch,                                   FILE_LIST_DIRECTORY,                                   FILE_SHARE_READ | FILE_SHARE_DELETE |                                     FILE_SHARE_WRITE,                                   NULL,                                   OPEN_EXISTING,                                   FILE_FLAG_BACKUP_SEMANTICS |                                     FILE_FLAG_OVERLAPPED,                                   NULL);  if (dir) {    uv__free(dir);    dir = NULL;  }  if (handle->dir_handle == INVALID_HANDLE_VALUE) {    last_error = GetLastError();    goto error;  }  if (CreateIoCompletionPort(handle->dir_handle,                             handle->loop->iocp,                             (ULONG_PTR)handle,                             0) == NULL) {    last_error = GetLastError();    goto error;  }//.........这里部分代码省略.........
开发者ID:ComputerVisionWorks,项目名称:libsourcey,代码行数:101,


示例24: uv__set_sys_error

void uv__set_sys_error(uv_loop_t* loop, int sys_error) {  loop->last_err.code = uv_translate_sys_error(sys_error);  loop->last_err.sys_errno_ = sys_error;}
开发者ID:Laner,项目名称:gitbin,代码行数:4,


示例25: uv_set_sys_error

void uv_set_sys_error(int sys_errno) {  LOOP->last_error.code = uv_translate_sys_error(sys_errno);  LOOP->last_error.sys_errno_ = sys_errno;}
开发者ID:changloong,项目名称:gool,代码行数:4,


示例26: uv_getaddrinfo

//.........这里部分代码省略.........  if (service != NULL) {    servicesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8,                                                   0,                                                   service,                                                   -1,                                                   NULL,                                                   0) *                               sizeof(WCHAR));    if (servicesize == 0) {      err = GetLastError();      goto error;    }  }  if (hints != NULL) {    hintssize = ALIGNED_SIZE(sizeof(struct addrinfoW));  }  /* allocate memory for inputs, and partition it as needed */  alloc_ptr = (char*)uv__malloc(nodesize + servicesize + hintssize);  if (!alloc_ptr) {    err = WSAENOBUFS;    goto error;  }  /* save alloc_ptr now so we can free if error */  req->alloc = (void*)alloc_ptr;  /* Convert node string to UTF16 into allocated memory and save pointer in the   * request. */  if (node != NULL) {    req->node = (WCHAR*)alloc_ptr;    if (MultiByteToWideChar(CP_UTF8,                            0,                            node,                            -1,                            (WCHAR*) alloc_ptr,                            nodesize / sizeof(WCHAR)) == 0) {      err = GetLastError();      goto error;    }    alloc_ptr += nodesize;  } else {    req->node = NULL;  }  /* Convert service string to UTF16 into allocated memory and save pointer in   * the req. */  if (service != NULL) {    req->service = (WCHAR*)alloc_ptr;    if (MultiByteToWideChar(CP_UTF8,                            0,                            service,                            -1,                            (WCHAR*) alloc_ptr,                            servicesize / sizeof(WCHAR)) == 0) {      err = GetLastError();      goto error;    }    alloc_ptr += servicesize;  } else {    req->service = NULL;  }  /* copy hints to allocated memory and save pointer in req */  if (hints != NULL) {    req->addrinfow = (struct addrinfoW*)alloc_ptr;    req->addrinfow->ai_family = hints->ai_family;    req->addrinfow->ai_socktype = hints->ai_socktype;    req->addrinfow->ai_protocol = hints->ai_protocol;    req->addrinfow->ai_flags = hints->ai_flags;    req->addrinfow->ai_addrlen = 0;    req->addrinfow->ai_canonname = NULL;    req->addrinfow->ai_addr = NULL;    req->addrinfow->ai_next = NULL;  } else {    req->addrinfow = NULL;  }  uv__req_register(loop, req);  if (getaddrinfo_cb) {    uv__work_submit(loop,                    &req->work_req,                    UV__WORK_SLOW_IO,                    uv__getaddrinfo_work,                    uv__getaddrinfo_done);    return 0;  } else {    uv__getaddrinfo_work(&req->work_req);    uv__getaddrinfo_done(&req->work_req, 0);    return req->retcode;  }error:  if (req != NULL) {    uv__free(req->alloc);    req->alloc = NULL;  }  return uv_translate_sys_error(err);}
开发者ID:AlexanderPankiv,项目名称:node,代码行数:101,


示例27: uv_process_udp_recv_req

void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,    uv_req_t* req) {  uv_buf_t buf;  int partial;  assert(handle->type == UV_UDP);  handle->flags &= ~UV_HANDLE_READ_PENDING;  if (!REQ_SUCCESS(req)) {    DWORD err = GET_REQ_SOCK_ERROR(req);    if (err == WSAEMSGSIZE) {      /* Not a real error, it just indicates that the received packet was       * bigger than the receive buffer. */    } else if (err == WSAECONNRESET || err == WSAENETRESET) {      /* A previous sendto operation failed; ignore this error. If zero-reading       * we need to call WSARecv/WSARecvFrom _without_ the. MSG_PEEK flag to       * clear out the error queue. For nonzero reads, immediately queue a new       * receive. */      if (!(handle->flags & UV_HANDLE_ZERO_READ)) {        goto done;      }    } else {      /* A real error occurred. Report the error to the user only if we're       * currently reading. */      if (handle->flags & UV_HANDLE_READING) {        uv_udp_recv_stop(handle);        buf = (handle->flags & UV_HANDLE_ZERO_READ) ?              uv_buf_init(NULL, 0) : handle->recv_buffer;        handle->recv_cb(handle, uv_translate_sys_error(err), &buf, NULL, 0);      }      goto done;    }  }  if (!(handle->flags & UV_HANDLE_ZERO_READ)) {    /* Successful read */    partial = !REQ_SUCCESS(req);    handle->recv_cb(handle,                    req->u.io.overlapped.InternalHigh,                    &handle->recv_buffer,                    (const struct sockaddr*) &handle->recv_from,                    partial ? UV_UDP_PARTIAL : 0);  } else if (handle->flags & UV_HANDLE_READING) {    DWORD bytes, err, flags;    struct sockaddr_storage from;    int from_len;    /* Do a nonblocking receive.     * TODO: try to read multiple datagrams at once. FIONREAD maybe? */    buf = uv_buf_init(NULL, 0);    handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);    if (buf.base == NULL || buf.len == 0) {      handle->recv_cb(handle, UV_ENOBUFS, &buf, NULL, 0);      goto done;    }    assert(buf.base != NULL);    memset(&from, 0, sizeof from);    from_len = sizeof from;    flags = 0;    if (WSARecvFrom(handle->socket,                    (WSABUF*)&buf,                    1,                    &bytes,                    &flags,                    (struct sockaddr*) &from,                    &from_len,                    NULL,                    NULL) != SOCKET_ERROR) {      /* Message received */      handle->recv_cb(handle, bytes, &buf, (const struct sockaddr*) &from, 0);    } else {      err = WSAGetLastError();      if (err == WSAEMSGSIZE) {        /* Message truncated */        handle->recv_cb(handle,                        bytes,                        &buf,                        (const struct sockaddr*) &from,                        UV_UDP_PARTIAL);      } else if (err == WSAEWOULDBLOCK) {        /* Kernel buffer empty */        handle->recv_cb(handle, 0, &buf, NULL, 0);      } else if (err == WSAECONNRESET || err == WSAENETRESET) {        /* WSAECONNRESET/WSANETRESET is ignored because this just indicates         * that a previous sendto operation failed.         */        handle->recv_cb(handle, 0, &buf, NULL, 0);      } else {        /* Any other error that we want to report back to the user. */        uv_udp_recv_stop(handle);        handle->recv_cb(handle, uv_translate_sys_error(err), &buf, NULL, 0);      }    }  }//.........这里部分代码省略.........
开发者ID:ajafff,项目名称:node,代码行数:101,


示例28: uv_tcp_endgame

void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {  int err;  unsigned int i;  uv_tcp_accept_t* req;  if (handle->flags & UV_HANDLE_CONNECTION &&      handle->shutdown_req != NULL &&      handle->write_reqs_pending == 0) {    UNREGISTER_HANDLE_REQ(loop, handle, handle->shutdown_req);    err = 0;    if (handle->flags & UV__HANDLE_CLOSING) {      err = ERROR_OPERATION_ABORTED;    } else if (shutdown(handle->socket, SD_SEND) == SOCKET_ERROR) {      err = WSAGetLastError();    }    if (handle->shutdown_req->cb) {      handle->shutdown_req->cb(handle->shutdown_req,                               uv_translate_sys_error(err));    }    handle->shutdown_req = NULL;    DECREASE_PENDING_REQ_COUNT(handle);    return;  }  if (handle->flags & UV__HANDLE_CLOSING &&      handle->reqs_pending == 0) {    assert(!(handle->flags & UV_HANDLE_CLOSED));    if (!(handle->flags & UV_HANDLE_TCP_SOCKET_CLOSED)) {      closesocket(handle->socket);      handle->flags |= UV_HANDLE_TCP_SOCKET_CLOSED;    }    if (!(handle->flags & UV_HANDLE_CONNECTION) && handle->accept_reqs) {      if (handle->flags & UV_HANDLE_EMULATE_IOCP) {        for (i = 0; i < uv_simultaneous_server_accepts; i++) {          req = &handle->accept_reqs[i];          if (req->wait_handle != INVALID_HANDLE_VALUE) {            pUnregisterWait(req->wait_handle);            req->wait_handle = INVALID_HANDLE_VALUE;          }          if (req->event_handle) {            CloseHandle(req->event_handle);            req->event_handle = NULL;          }        }      }      free(handle->accept_reqs);      handle->accept_reqs = NULL;    }    if (handle->flags & UV_HANDLE_CONNECTION &&        handle->flags & UV_HANDLE_EMULATE_IOCP) {      if (handle->read_req.wait_handle != INVALID_HANDLE_VALUE) {        pUnregisterWait(handle->read_req.wait_handle);        handle->read_req.wait_handle = INVALID_HANDLE_VALUE;      }      if (handle->read_req.event_handle) {        CloseHandle(handle->read_req.event_handle);        handle->read_req.event_handle = NULL;      }    }    uv__handle_close(handle);    loop->active_tcp_streams--;  }}
开发者ID:flybird119,项目名称:libuv-vc6,代码行数:72,


示例29: uv_process_getaddrinfo_req

/* * Called from uv_run when complete. Call user specified callback * then free returned addrinfo * Returned addrinfo strings are converted from UTF-16 to UTF-8. * * To minimize allocation we calculate total size required, * and copy all structs and referenced strings into the one block. * Each size calculation is adjusted to avoid unaligned pointers. */void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,    uv_req_t* req) {  int addrinfo_len = 0;  int name_len = 0;  size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo));  struct addrinfoW* addrinfow_ptr;  struct addrinfo* addrinfo_ptr;  char* alloc_ptr = NULL;  char* cur_ptr = NULL;  uv_err_code uv_ret;  /* release input parameter memory */  if (handle->alloc != NULL) {    free(handle->alloc);    handle->alloc = NULL;  }  uv_ret = uv_translate_eai_error(handle->retcode);  if (handle->retcode == 0) {    /* convert addrinfoW to addrinfo */    /* first calculate required length */    addrinfow_ptr = handle->res;    while (addrinfow_ptr != NULL) {      addrinfo_len += addrinfo_struct_len +          ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);      if (addrinfow_ptr->ai_canonname != NULL) {        name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0);        if (name_len == 0) {          uv_ret = uv_translate_sys_error(GetLastError());          goto complete;        }        addrinfo_len += ALIGNED_SIZE(name_len);      }      addrinfow_ptr = addrinfow_ptr->ai_next;    }    /* allocate memory for addrinfo results */    alloc_ptr = (char*)malloc(addrinfo_len);    /* do conversions */    if (alloc_ptr != NULL) {      cur_ptr = alloc_ptr;      addrinfow_ptr = handle->res;      while (addrinfow_ptr != NULL) {        /* copy addrinfo struct data */        assert(cur_ptr + addrinfo_struct_len <= alloc_ptr + addrinfo_len);        addrinfo_ptr = (struct addrinfo*)cur_ptr;        addrinfo_ptr->ai_family = addrinfow_ptr->ai_family;        addrinfo_ptr->ai_socktype = addrinfow_ptr->ai_socktype;        addrinfo_ptr->ai_protocol = addrinfow_ptr->ai_protocol;        addrinfo_ptr->ai_flags = addrinfow_ptr->ai_flags;        addrinfo_ptr->ai_addrlen = addrinfow_ptr->ai_addrlen;        addrinfo_ptr->ai_canonname = NULL;        addrinfo_ptr->ai_addr = NULL;        addrinfo_ptr->ai_next = NULL;        cur_ptr += addrinfo_struct_len;        /* copy sockaddr */        if (addrinfo_ptr->ai_addrlen > 0) {          assert(cur_ptr + addrinfo_ptr->ai_addrlen <=                 alloc_ptr + addrinfo_len);          memcpy(cur_ptr, addrinfow_ptr->ai_addr, addrinfo_ptr->ai_addrlen);          addrinfo_ptr->ai_addr = (struct sockaddr*)cur_ptr;          cur_ptr += ALIGNED_SIZE(addrinfo_ptr->ai_addrlen);        }        /* convert canonical name to UTF-8 */        if (addrinfow_ptr->ai_canonname != NULL) {          name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname,                                      -1,                                      NULL,                                      0);          assert(name_len > 0);          assert(cur_ptr + name_len <= alloc_ptr + addrinfo_len);          name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname,                                      -1,                                      cur_ptr,                                      name_len);          assert(name_len > 0);          addrinfo_ptr->ai_canonname = cur_ptr;          cur_ptr += ALIGNED_SIZE(name_len);        }        assert(cur_ptr <= alloc_ptr + addrinfo_len);        /* set next ptr */        addrinfow_ptr = addrinfow_ptr->ai_next;        if (addrinfow_ptr != NULL) {          addrinfo_ptr->ai_next = (struct addrinfo*)cur_ptr;        }//.........这里部分代码省略.........
开发者ID:178620086,项目名称:Node4Android,代码行数:101,


示例30: uv_getaddrinfo

//.........这里部分代码省略.........  uv_req_init(loop, (uv_req_t*)req);  req->getaddrinfo_cb = getaddrinfo_cb;  req->res = NULL;  req->type = UV_GETADDRINFO;  req->loop = loop;  req->retcode = 0;  /* calculate required memory size for all input values */  if (node != NULL) {    nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(WCHAR));    if (nodesize == 0) {      err = GetLastError();      goto error;    }  }  if (service != NULL) {    servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) *                               sizeof(WCHAR));    if (servicesize == 0) {      err = GetLastError();      goto error;    }  }  if (hints != NULL) {    hintssize = ALIGNED_SIZE(sizeof(struct addrinfoW));  }  /* allocate memory for inputs, and partition it as needed */  alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize);  if (!alloc_ptr) {    err = WSAENOBUFS;    goto error;  }  /* save alloc_ptr now so we can free if error */  req->alloc = (void*)alloc_ptr;  /* convert node string to UTF16 into allocated memory and save pointer in */  /* the reques. */  if (node != NULL) {    req->node = (WCHAR*)alloc_ptr;    if (uv_utf8_to_utf16(node,                         (WCHAR*) alloc_ptr,                         nodesize / sizeof(WCHAR)) == 0) {      err = GetLastError();      goto error;    }    alloc_ptr += nodesize;  } else {    req->node = NULL;  }  /* convert service string to UTF16 into allocated memory and save pointer */  /* in the req. */  if (service != NULL) {    req->service = (WCHAR*)alloc_ptr;    if (uv_utf8_to_utf16(service,                         (WCHAR*) alloc_ptr,                         servicesize / sizeof(WCHAR)) == 0) {      err = GetLastError();      goto error;    }    alloc_ptr += servicesize;  } else {    req->service = NULL;  }  /* copy hints to allocated memory and save pointer in req */  if (hints != NULL) {    req->hints = (struct addrinfoW*)alloc_ptr;    req->hints->ai_family = hints->ai_family;    req->hints->ai_socktype = hints->ai_socktype;    req->hints->ai_protocol = hints->ai_protocol;    req->hints->ai_flags = hints->ai_flags;    req->hints->ai_addrlen = 0;    req->hints->ai_canonname = NULL;    req->hints->ai_addr = NULL;    req->hints->ai_next = NULL;  } else {    req->hints = NULL;  }  uv__work_submit(loop,                  &req->work_req,                  uv__getaddrinfo_work,                  uv__getaddrinfo_done);  uv__req_register(loop, req);  return 0;error:  if (req != NULL && req->alloc != NULL) {    free(req->alloc);  }  return uv_translate_sys_error(err);}
开发者ID:353355756,项目名称:node,代码行数:101,



注:本文中的uv_translate_sys_error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ uv_unref函数代码示例
C++ uv_timer_stop函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。