Beispiel #1
0
void ConnectionContext::Close()
{
	sync_set(&close_flag_, 1);
	if (ssl_stream_)
		ssl_stream_->close();
	else
		tcp_stream_->close();
}
Beispiel #2
0
void socket_ops::connect(iocp::socket &socket,
												 iocp::operation *op,
												 const iocp::address &addr,
												 unsigned short port)
{
	iocp::service &service = socket.service();
	service.work_started();
	iocp::error_code ec = socket.open();
  if (ec.value() == iocp::error::already_open)
    ec.set_value(0);
	// IOCP needs socket to bind an address before calling ConnectEx
	if (!ec && !sync_get(&socket.already_binded_)) {
		ec = service.bind(socket.socket_, iocp::address(0U), 0);
    if (!ec)
      sync_set(&socket.already_binded_, 1);
  }
	if (ec)
		service.on_completion(op, ec);
	else
		service.connect(socket.socket_, op, addr, port);
}
Beispiel #3
0
		AIO_COMM_API void set_global_heap(heap& h) {sync_set(g_global_heap, &h);}
Beispiel #4
0
int transfer_instant_pull(const char *path)
{
    int res;
    char *pc, *pr;
    size_t p_len = strlen(path);
    bool path_equal = false;

    VERBOSE("instant_pulling %s", path);

    pthread_mutex_lock(&m_instant_pull);

    worker_block();

    pr = remote_path2(path, p_len);
    pc = cache_path2(path, p_len);

    pthread_mutex_lock(&m_transfer);
    if (t_state.active)
        path_equal = !strcmp(path, t_state.job->path);
    pthread_mutex_unlock(&m_transfer);

    /* requested file is already being transfered (normally).
       just continue the transfer until it is finished */
    if (path_equal)
    {
        /* continuing a running transfer() only works if !worker_blocked() */
        worker_unblock();
        do
        {
            res = transfer(NULL, NULL);
        }
        while (ONLINE && res == TRANSFER_OK);

        res = (res == TRANSFER_FINISH) ? 0 : 1;
        worker_block();
    }
    else
    {
        res = copy_file(pr, pc);

        /* if copy_file failed, possibly because the file's directory didn't
           exist in the cache yet. create it and retry */
        if (res && errno == ENOENT)
        {
            char *dir = dirname_r(path);

            if (dir)
            {
                transfer_pull_dir(dir);
                free(dir);
                res = copy_file(pr, pc);
            }
        }
    }

    worker_unblock();

    copy_attrs(pr, pc);
    free(pr);
    free(pc);

    /* if copying failed, return error and dont set sync */
    if (res)
    {
        ERROR("instant_pull on %s FAILED", path);
        pthread_mutex_unlock(&m_instant_pull);
        return -1;
    }

    /* file is in sync now */
    job_delete(path, JOB_PULL);
    sync_set(path, 0);

    pthread_mutex_unlock(&m_instant_pull);
    return 0;
}