コード例 #1
0
ファイル: tcp.c プロジェクト: InfamousNugz/dnscrypt-proxy
int uv__tcp_connect6(uv_connect_t* req,
                     uv_tcp_t* handle,
                     struct sockaddr_in6 address,
                     uv_connect_cb cb) {
  uv_loop_t* loop = handle->loop;
  int addrsize = sizeof(struct sockaddr_in6);
  BOOL success;
  DWORD bytes;

  if (!uv_allow_ipv6) {
    uv__set_sys_error(loop, WSAEAFNOSUPPORT);
    return -1;
  }

  if (handle->flags & UV_HANDLE_BIND_ERROR) {
    uv__set_sys_error(loop, handle->bind_error);
    return -1;
  }

  if (!(handle->flags & UV_HANDLE_BOUND) &&
      uv_tcp_bind6(handle, uv_addr_ip6_any_) < 0)
    return -1;

  if (!handle->func_connectex) {
    if(!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
      uv__set_sys_error(loop, WSAEAFNOSUPPORT);
      return -1;
    }
  }

  uv_req_init(loop, (uv_req_t*) req);
  req->type = UV_CONNECT;
  req->handle = (uv_stream_t*) handle;
  req->cb = cb;
  memset(&req->overlapped, 0, sizeof(req->overlapped));

  success = handle->func_connectex(handle->socket,
                                   (struct sockaddr*) &address,
                                   addrsize,
                                   NULL,
                                   0,
                                   &bytes,
                                   &req->overlapped);

  if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
    handle->reqs_pending++;
    uv_ref(loop);
    uv_insert_pending_req(loop, (uv_req_t*)req);
  } else if (UV_SUCCEEDED_WITH_IOCP(success)) {
    handle->reqs_pending++;
    uv_ref(loop);
  } else {
    uv__set_sys_error(loop, WSAGetLastError());
    return -1;
  }

  return 0;
}
コード例 #2
0
ファイル: cef_loop.cpp プロジェクト: 276361270/appjs
void CefLoop::Run() {

  if( !CefLoop::initialized_ || CefLoop::running_ ) return;

#if NODE_VERSION_AT_LEAST(0, 7, 9)
  uv_ref((uv_handle_t *)&g_async);
#else
  uv_ref(uv_default_loop());
#endif

  uv_timer_start(&timer,RunLoop,1,1);
  
  CefLoop::running_ = true;
}
コード例 #3
0
ファイル: main.c プロジェクト: nkatsaros/stronglink
static void term(void *const unused) {
	fprintf(stderr, "\nStopping StrongLink server...\n");

	uv_ref((uv_handle_t *)sigint);
	uv_signal_stop(sigint);
	async_close((uv_handle_t *)sigint);

	SLNRepoPullsStop(repo);
	HTTPServerClose(server_raw);
	HTTPServerClose(server_tls);

	uv_ref((uv_handle_t *)sigpipe);
	uv_signal_stop(sigpipe);
	uv_close((uv_handle_t *)sigpipe, NULL);
}
コード例 #4
0
ファイル: syncsocket.c プロジェクト: stmuk/MoarVM
static void socket_connect(MVMThreadContext *tc, MVMOSHandle *h, MVMString *host, MVMint64 port) {
    MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)h->body.data;
    if (!data->ss.handle) {
        struct sockaddr *dest    = MVM_io_resolve_host_name(tc, host, port);
        uv_tcp_t        *socket  = MVM_malloc(sizeof(uv_tcp_t));
        uv_connect_t    *connect = MVM_malloc(sizeof(uv_connect_t));
        int r;

        data->ss.cur_tc = tc;
        connect->data   = data;
        if ((r = uv_tcp_init(tc->loop, socket)) < 0 ||
                (r = uv_tcp_connect(connect, socket, dest, on_connect)) < 0) {
            MVM_free(socket);
            MVM_free(connect);
            MVM_free(dest);
            MVM_exception_throw_adhoc(tc, "Failed to connect: %s", uv_strerror(r));
        }
        uv_ref((uv_handle_t *)socket);
        uv_run(tc->loop, UV_RUN_DEFAULT);

        data->ss.handle = (uv_stream_t *)socket;

        MVM_free(connect);
        MVM_free(dest);
    }
    else {
        MVM_exception_throw_adhoc(tc, "Socket is already bound or connected");
    }
}
コード例 #5
0
ファイル: fs.c プロジェクト: adrienschuler/node
int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf,
    size_t length, off_t offset, uv_fs_cb cb) {
  uv_fs_req_init(loop, req, UV_FS_WRITE, NULL, cb);

  if (cb) {
    /* async */
    uv_ref(loop);
    req->eio = eio_write(file, buf, length, offset, EIO_PRI_DEFAULT,
        uv__fs_after, req);
    if (!req->eio) {
      uv_err_new(loop, ENOMEM);
      return -1;
    }

  } else {
    /* sync */
    req->result = offset < 0 ?
        write(file, buf, length) :
        pwrite(file, buf, length, offset);

    if (req->result < 0) {
      uv_err_new(loop, errno);
      return -1;
    }
  }

  return 0;
}
コード例 #6
0
ファイル: fs.c プロジェクト: adrienschuler/node
int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
    int mode, uv_fs_cb cb) {
  uv_fs_req_init(loop, req, UV_FS_OPEN, path, cb);

  if (cb) {
    /* async */
    uv_ref(loop);
    req->eio = eio_open(path, flags, mode, EIO_PRI_DEFAULT, uv__fs_after, req);
    if (!req->eio) {
      uv_err_new(loop, ENOMEM);
      return -1;
    }

  } else {
    /* sync */
    req->result = open(path, flags, mode);
    if (req->result < 0) {
      uv_err_new(loop, errno);
      return -1;
    }

    uv__cloexec(req->result, 1);
  }

  return 0;
}
コード例 #7
0
ファイル: syncsocket.c プロジェクト: grondilu/MoarVM
static MVMObject * socket_accept(MVMThreadContext *tc, MVMOSHandle *h) {
    MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)h->body.data;

    while (!data->accept_server) {
        uv_ref((uv_handle_t *)data->ss.handle);
        uv_run(tc->loop, UV_RUN_DEFAULT);
    }

    /* Check the accept worked out. */
    if (data->accept_status < 0) {
        MVM_exception_throw_adhoc(tc, "Failed to listen: unknown error");
    }
    else {
        uv_tcp_t *client    = malloc(sizeof(uv_tcp_t));
        uv_stream_t *server = data->accept_server;
        int r;
        uv_tcp_init(tc->loop, client);
        data->accept_server = NULL;
        if ((r = uv_accept(server, (uv_stream_t *)client)) == 0) {
            MVMOSHandle         * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIO);
            MVMIOSyncSocketData * const data   = calloc(1, sizeof(MVMIOSyncSocketData));
            data->ss.handle   = (uv_stream_t *)client;
            data->ss.encoding = MVM_encoding_type_utf8;
            data->ss.sep      = '\n';
            result->body.ops  = &op_table;
            result->body.data = data;
            return (MVMObject *)result;
        }
        else {
            uv_close((uv_handle_t*)client, NULL);
            free(client);
            MVM_exception_throw_adhoc(tc, "Failed to accept: %s", uv_strerror(r));
        }
    }
}
コード例 #8
0
ファイル: syncstream.c プロジェクト: BlastarIndia/MoarVM
MVMint64 MVM_io_syncstream_write_str(MVMThreadContext *tc, MVMOSHandle *h, MVMString *str, MVMint64 newline) {
    MVMIOSyncStreamData *data = (MVMIOSyncStreamData *)h->body.data;
    MVMuint8 *output;
    MVMint64 output_size;
    uv_write_t *req;
    uv_buf_t write_buf;
    int r;

    output = MVM_string_encode(tc, str, 0, -1, &output_size, data->encoding);
    if (newline) {
        output = (MVMuint8 *)realloc(output, ++output_size);
        output[output_size - 1] = '\n';
    }
    req = malloc(sizeof(uv_write_t));
    write_buf = uv_buf_init(output, output_size);
    uv_ref((uv_handle_t *)data->handle);
    if ((r = uv_write(req, data->handle, &write_buf, 1, write_cb)) < 0) {
        uv_unref((uv_handle_t *)data->handle);
        free(req);
        free(output);
        MVM_exception_throw_adhoc(tc, "Failed to write string to stream: %s", uv_strerror(r));
    }
    else {
        uv_run(tc->loop, UV_RUN_DEFAULT);
        free(output);
    }

    data->total_bytes_written += output_size;
    return output_size;
}
コード例 #9
0
void NodeMap::startRender(NodeMap::RenderOptions options) {
    view.resize(options.width, options.height);
    map->update(mbgl::Update::Dimensions);
    map->setClasses(options.classes);
    map->setLatLngZoom(mbgl::LatLng(options.latitude, options.longitude), options.zoom);
    map->setBearing(options.bearing);
    map->setPitch(options.pitch);
    map->setDebug(options.debugOptions);

    map->renderStill([this](const std::exception_ptr eptr, mbgl::PremultipliedImage&& result) {
        if (eptr) {
            error = std::move(eptr);
            uv_async_send(async);
        } else {
            assert(!image.data);
            image = std::move(result);
            uv_async_send(async);
        }
    });

    // Retain this object, otherwise it might get destructed before we are finished rendering the
    // still image.
    Ref();

    // Similarly, we're now waiting for the async to be called, so we need to make sure that it
    // keeps the loop alive.
    uv_ref(reinterpret_cast<uv_handle_t *>(async));
}
コード例 #10
0
void computeHomography(
    const vector<Vector3d>& f_ref,
    const vector<Vector3d>& f_cur,
    double focal_length,
    double reprojection_threshold,
    vector<int>& inliers,
    vector<Vector3d>& xyz_in_cur,
    SE3& T_cur_from_ref)
{
  vector<Vector2d, aligned_allocator<Vector2d> > uv_ref(f_ref.size());
  vector<Vector2d, aligned_allocator<Vector2d> > uv_cur(f_cur.size());
  for(size_t i=0, i_max=f_ref.size(); i<i_max; ++i)
  {
    uv_ref[i] = vk::project2d(f_ref[i]);
    uv_cur[i] = vk::project2d(f_cur[i]);
  }
  vk::Homography Homography(uv_ref, uv_cur, focal_length, reprojection_threshold);
  Homography.computeSE3fromMatches();
  vector<int> outliers;
  vk::computeInliers(f_cur, f_ref,
                     Homography.T_c2_from_c1.rotation_matrix(), Homography.T_c2_from_c1.translation(),
                     reprojection_threshold, focal_length,
                     xyz_in_cur, inliers, outliers);
  T_cur_from_ref = Homography.T_c2_from_c1;
}
コード例 #11
0
ファイル: process.c プロジェクト: HenryRawas/libuv
static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) {
  handle->type = UV_PROCESS;
  handle->loop = loop;
  handle->flags = 0;
  handle->exit_cb = NULL;
  handle->pid = 0;
  handle->exit_signal = 0;
  handle->wait_handle = INVALID_HANDLE_VALUE;
  handle->process_handle = INVALID_HANDLE_VALUE;
  handle->close_handle = INVALID_HANDLE_VALUE;
  handle->child_stdio[0] = INVALID_HANDLE_VALUE;
  handle->child_stdio[1] = INVALID_HANDLE_VALUE;
  handle->child_stdio[2] = INVALID_HANDLE_VALUE;

  uv_req_init(loop, (uv_req_t*)&handle->exit_req);
  handle->exit_req.type = UV_PROCESS_EXIT;
  handle->exit_req.data = handle;
  uv_req_init(loop, (uv_req_t*)&handle->close_req);
  handle->close_req.type = UV_PROCESS_CLOSE;
  handle->close_req.data = handle;

  loop->counters.handle_init++;
  loop->counters.process_init++;

  uv_ref(loop);
}
コード例 #12
0
ファイル: EventLoop.cpp プロジェクト: glandu2/librzu
EventLoop::~EventLoop() {
	uv_ref((uv_handle_t*) &deleteObjectsHandle);
	uv_prepare_stop(&deleteObjectsHandle);
	uv_close((uv_handle_t*) &deleteObjectsHandle, nullptr);

	// Wait remaining handle to close
	uv_run(&loop, UV_RUN_DEFAULT);

	if(uv_loop_alive(&loop)) {
		log(LL_Warning, "Loop still used but delete requested, handles:\n");
		uv_walk(&loop,
		        [](uv_handle_t* handle, void* arg) {
			        EventLoop* self = (EventLoop*) arg;
			        const char* type;
			        switch(handle->type) {
#define X(uc, lc) \
	case UV_##uc: \
		type = #lc; \
		break;
				        UV_HANDLE_TYPE_MAP(X)
#undef X
				        default:
					        type = "<unknown>";
			        }

			        self->log(LL_Warning, "  [%08X] %s %p\n", handle->flags, type, handle);
		        },
		        this);
コード例 #13
0
ファイル: handle.c プロジェクト: AsamQi/couv
static int couv_ref(lua_State *L) {
  uv_handle_t *handle;

  handle = couvL_checkudataclass(L, 1, COUV_HANDLE_MTBL_NAME);
  uv_ref(handle);
  return 0;
}
コード例 #14
0
ファイル: HTTPConnection.c プロジェクト: rmoorman/stronglink
ssize_t HTTPConnectionReadRequest(HTTPConnectionRef const conn, HTTPMethod *const method, str_t *const out, size_t const max) {
	if(!conn) return UV_EINVAL;
	if(!max) return UV_EINVAL;
	uv_buf_t buf[1];
	int rc;
	HTTPEvent type;
	size_t len = 0;
	for(;;) {
		// Use unref because we shouldn't block the server
		// on a request that may never arrive.
		uv_unref((uv_handle_t *)conn->stream);
		rc = HTTPConnectionPeek(conn, &type, buf);
		uv_ref((uv_handle_t *)conn->stream);
		if(rc < 0) return rc;
		if(HTTPHeaderField == type || HTTPHeadersComplete == type) break;
		HTTPConnectionPop(conn, buf->len);
		if(HTTPMessageBegin == type) continue;
		if(HTTPURL != type) {
			assertf(0, "Unexpected HTTP event %d", type);
			return UV_UNKNOWN;
		}
		if(len+buf->len+1 > max) return UV_EMSGSIZE;
		memcpy(out+len, buf->base, buf->len);
		len += buf->len;
		out[len] = '\0';
	}
	*method = conn->parser->method;
	return (ssize_t)len;
}
コード例 #15
0
ファイル: process.c プロジェクト: changloong/gool
static void uv_process_init(uv_process_t* handle) {
  handle->type = UV_PROCESS;
  handle->flags = 0;
  handle->error = uv_ok_;
  handle->exit_cb = NULL;
  handle->pid = 0;
  handle->exit_signal = 0;
  handle->wait_handle = INVALID_HANDLE_VALUE;
  handle->process_handle = INVALID_HANDLE_VALUE;
  handle->close_handle = INVALID_HANDLE_VALUE;
  handle->stdio_pipes[0].server_pipe = NULL;
  handle->stdio_pipes[0].child_pipe = INVALID_HANDLE_VALUE;
  handle->stdio_pipes[1].server_pipe = NULL;
  handle->stdio_pipes[1].child_pipe = INVALID_HANDLE_VALUE;
  handle->stdio_pipes[2].server_pipe = NULL;
  handle->stdio_pipes[2].child_pipe = INVALID_HANDLE_VALUE;

  uv_req_init((uv_req_t*)&handle->exit_req);
  handle->exit_req.type = UV_PROCESS_EXIT;
  handle->exit_req.data = handle;
  uv_req_init((uv_req_t*)&handle->close_req);
  handle->close_req.type = UV_PROCESS_CLOSE;
  handle->close_req.data = handle;

  uv_counters()->handle_init++;
  uv_counters()->process_init++;

  uv_ref();
}
コード例 #16
0
ファイル: fs-event.c プロジェクト: Laner/gitbin
static void uv_fs_event_init_handle(uv_loop_t* loop, uv_fs_event_t* handle,
    const char* filename, uv_fs_event_cb cb) {
  handle->type = UV_FS_EVENT;
  handle->loop = loop;
  handle->flags = 0;
  handle->cb = cb;
  handle->is_path_dir = 0;
  handle->dir_handle = INVALID_HANDLE_VALUE;
  handle->buffer = NULL;
  handle->req_pending = 0;
  handle->filew = NULL;
  handle->short_filew = NULL;

  uv_req_init(loop, (uv_req_t*)&handle->req);
  handle->req.type = UV_FS_EVENT_REQ;
  handle->req.data = (void*)handle;

  handle->filename = strdup(filename);
  if (!handle->filename) {
    uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
  }

  loop->counters.handle_init++;
  loop->counters.fs_event_init++;

  uv_ref(loop);
}
コード例 #17
0
ファイル: handle.cpp プロジェクト: dannyzhu/jlibuv
/*
 * Class:     com_oracle_libuv_handles_Handle
 * Method:    _ref
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_com_oracle_libuv_handles_Handle__1ref
  (JNIEnv *env, jobject that, jlong ptr) {

  assert(ptr);
  uv_handle_t* handle = reinterpret_cast<uv_handle_t*>(ptr);
  uv_ref(handle);
}
コード例 #18
0
ファイル: fs.c プロジェクト: adrienschuler/node
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
  uv_fs_req_init(loop, req, UV_FS_FSTAT, NULL, cb);

  if (cb) {
    /* async */
    uv_ref(loop);
    req->eio = eio_fstat(file, EIO_PRI_DEFAULT, uv__fs_after, req);

    if (!req->eio) {
      uv_err_new(loop, ENOMEM);
      return -1;
    }

  } else {
    /* sync */
    req->result = fstat(file, &req->statbuf);

    if (req->result < 0) {
      uv_err_new(loop, errno);
      return -1;
    }

    req->ptr = &req->statbuf;
  }

  return 0;
}
コード例 #19
0
ファイル: fs.c プロジェクト: adrienschuler/node
int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
    uv_fs_cb cb) {
  int r;
  struct dirent* entry;
  size_t size = 0;
  size_t d_namlen = 0;

  uv_fs_req_init(loop, req, UV_FS_READDIR, path, cb);

  if (cb) {
    /* async */
    uv_ref(loop);
    req->eio = eio_readdir(path, flags, EIO_PRI_DEFAULT, uv__fs_after, req);
    if (!req->eio) {
      uv_err_new(loop, ENOMEM);
      return -1;
    }

  } else {
    /* sync */
    DIR* dir = opendir(path);
    if (!dir) {
      uv_err_new(loop, errno);
      req->result = -1;
      return -1;
    }

    /* req->result stores number of entries */
    req->result = 0;

    while ((entry = readdir(dir))) {
      d_namlen = strlen(entry->d_name);

      /* Skip . and .. */
      if ((d_namlen == 1 && entry->d_name[0] == '.') ||
          (d_namlen == 2 && entry->d_name[0] == '.' &&
           entry->d_name[1] == '.')) {
        continue;
      }

      req->ptr = realloc(req->ptr, size + d_namlen + 1);
      /* TODO check ENOMEM */
      memcpy((char*)req->ptr + size, entry->d_name, d_namlen);
      size += d_namlen;
      ((char*)req->ptr)[size] = '\0';
      size++;
      req->result++;
    }

    r = closedir(dir);
    if (r) {
      uv_err_new(loop, errno);
      req->result = -1;
      return -1;
    }
  }

  return 0;
}
コード例 #20
0
bool Handle::ref()
{
    if (!active())
        return false;

    uv_ref(ptr());
    return true;
}
コード例 #21
0
ファイル: handle.c プロジェクト: ayanamist/pyuv
static PyObject *
Handle_func_ref(Handle *self)
{
    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);
    uv_ref(self->uv_handle);
    Py_RETURN_NONE;
}
コード例 #22
0
void EventStream::add(Event * event) {
  uv_mutex_lock(&mutex);

  eventVector.push_back(event);
  uv_ref(reinterpret_cast<uv_handle_t *>(&async));
  uv_mutex_unlock(&mutex);

  uv_async_send(&async);
}
コード例 #23
0
ファイル: stream.c プロジェクト: changloong/gool
void uv_stream_init(uv_stream_t* handle) {
  handle->write_queue_size = 0;
  handle->flags = 0;
  handle->error = uv_ok_;

  uv_counters()->handle_init++;
  uv_counters()->stream_init++;

  uv_ref();
}
コード例 #24
0
ファイル: main.c プロジェクト: andreydelpozo2/stronglink
static void term(void *const unused) {
	fprintf(stderr, "\n");
	alogf("Stopping StrongLink server...\n");

	uv_ref((uv_handle_t *)sigint);
	uv_signal_stop(sigint);
	async_close((uv_handle_t *)sigint);

	SLNRepoPullsStop(repo);
	HTTPServerClose(server_raw);
	HTTPServerClose(server_tls);

	async_pool_enter(NULL);
	fflush(NULL); // Everything.
	async_pool_leave(NULL);

	uv_ref((uv_handle_t *)sigpipe);
	uv_signal_stop(sigpipe);
	uv_close((uv_handle_t *)sigpipe, NULL);
}
コード例 #25
0
ファイル: socksys.cpp プロジェクト: davidd2k/qminer
void TSockSys::RefLoop() { 
	IAssert(LoopRef == NULL);
	// create new timer
	LoopRef = (uv_timer_t*)malloc(sizeof(uv_timer_t));
	// initialize
	uv_timer_init(Loop, LoopRef);
	// start the timer
	uv_timer_start(LoopRef, LoopRefCallback, 0, 60000);
	// reference the timer
	uv_ref((uv_handle_t*)LoopRef); 
}
コード例 #26
0
ファイル: threadpool.c プロジェクト: BillBarnhill/node-custom
int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
    uv_after_work_cb after_work_cb) {
  uv_work_req_init(loop, req, work_cb, after_work_cb);

  if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) {
    uv_set_sys_error(loop, GetLastError());
    return -1;
  }

  uv_ref(loop);
  return 0;
}
コード例 #27
0
ファイル: udp.c プロジェクト: geraldfong/svprep
static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
    int bufcnt, struct sockaddr* addr, int addr_len, uv_udp_send_cb cb) {
  uv_loop_t* loop = handle->loop;
  DWORD result, bytes;

  uv_req_init(loop, (uv_req_t*) req);
  req->type = UV_UDP_SEND;
  req->handle = handle;
  req->cb = cb;
  memset(&req->overlapped, 0, sizeof(req->overlapped));

  result = WSASendTo(handle->socket,
                     (WSABUF*)bufs,
                     bufcnt,
                     &bytes,
                     0,
                     addr,
                     addr_len,
                     &req->overlapped,
                     NULL);

  if (UV_SUCCEEDED_WITHOUT_IOCP(result == 0)) {
    /* Request completed immediately. */
    req->queued_bytes = 0;
    handle->reqs_pending++;
    uv_ref(loop);
    uv_insert_pending_req(loop, (uv_req_t*)req);
  } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) {
    /* Request queued by the kernel. */
    req->queued_bytes = uv_count_bufs(bufs, bufcnt);
    handle->reqs_pending++;
    uv_ref(loop);
  } else {
    /* Send failed due to an error. */
    uv__set_sys_error(loop, WSAGetLastError());
    return -1;
  }

  return 0;
}
コード例 #28
0
ファイル: fs.c プロジェクト: adrienschuler/node
int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
    uv_fs_cb cb) {
  ssize_t size;
  int status;
  char* buf;

  status = -1;

  uv_fs_req_init(loop, req, UV_FS_READLINK, path, cb);

  if (cb) {
    if ((req->eio = eio_readlink(path, EIO_PRI_DEFAULT, uv__fs_after, req))) {
      uv_ref(loop);
      return 0;
    } else {
      uv_err_new(loop, ENOMEM);
      return -1;
    }
  } else {
    /* pathconf(_PC_PATH_MAX) may return -1 to signify that path
     * lengths have no upper limit or aren't suitable for malloc'ing.
     */
    if ((size = pathconf(path, _PC_PATH_MAX)) == -1) {
#if defined(PATH_MAX)
      size = PATH_MAX;
#else
      size = 4096;
#endif
    }

    if ((buf = malloc(size + 1)) == NULL) {
      uv_err_new(loop, ENOMEM);
      return -1;
    }

    if ((size = readlink(path, buf, size)) == -1) {
      req->errorno = errno;
      req->result = -1;
      free(buf);
    } else {
      /* Cannot conceivably fail since it shrinks the buffer. */
      buf = realloc(buf, size + 1);
      buf[size] = '\0';
      req->result = 0;
      req->ptr = buf;
    }

    return 0;
  }

  assert(0 && "unreachable");
}
コード例 #29
0
ファイル: decode.hpp プロジェクト: netconstructor/tilelive-s3
    DecodeBaton() :
        width(0),
        height(0),
        result(NULL),
        resultLength(0)
    {
#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 4
        ev_ref(EV_DEFAULT_UC);
#else
        this->request.data = this;
        uv_ref(uv_default_loop());
#endif
    }
コード例 #30
0
ファイル: core.c プロジェクト: Maxence/node
/* stub implementation of uv_getaddrinfo */
int uv_getaddrinfo(uv_loop_t* loop,
                   uv_getaddrinfo_t* handle,
                   uv_getaddrinfo_cb cb,
                   const char* hostname,
                   const char* service,
                   const struct addrinfo* hints) {
  eio_req* req;
  uv_eio_init(loop);

  if (handle == NULL || cb == NULL ||
      (hostname == NULL && service == NULL)) {
    uv__set_artificial_error(loop, UV_EINVAL);
    return -1;
  }

  uv__req_init(loop, (uv_req_t*)handle);
  handle->type = UV_GETADDRINFO;
  handle->loop = loop;
  handle->cb = cb;

  /* TODO don't alloc so much. */

  if (hints) {
    handle->hints = malloc(sizeof(struct addrinfo));
    memcpy(handle->hints, hints, sizeof(struct addrinfo));
  }
  else {
    handle->hints = NULL;
  }

  /* TODO security! check lengths, check return values. */

  handle->hostname = hostname ? strdup(hostname) : NULL;
  handle->service = service ? strdup(service) : NULL;
  handle->res = NULL;
  handle->retcode = 0;

  /* TODO check handle->hostname == NULL */
  /* TODO check handle->service == NULL */

  uv_ref(loop);

  req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT,
      uv_getaddrinfo_done, handle, &loop->uv_eio_channel);
  assert(req);
  assert(req->data == handle);

  return 0;
}