static void process_extended_fstatvfs(u_int32_t id) { int r, handle, fd; struct statvfs st; if ((r = get_handle(iqueue, &handle)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); debug("request %u: fstatvfs \"%s\" (handle %u)", id, handle_to_name(handle), handle); if ((fd = handle_to_fd(handle)) < 0) { send_status(id, SSH2_FX_FAILURE); return; } if (fstatvfs(fd, &st) != 0) send_status(id, errno_to_portable(errno)); else send_statvfs(id, &st); }
static ENGINE_ERROR_CODE mock_initialize(ENGINE_HANDLE* handle, const char* config_str) { struct mock_engine* se = get_handle(handle); assert(!se->initialized); assert(my_hash_ops.dupKey); if (strcmp(config_str, "no_alloc") != 0) { se->hashtbl = genhash_init(1, my_hash_ops); assert(se->hashtbl); } se->server->callback->register_callback((ENGINE_HANDLE*)se, ON_DISCONNECT, handle_disconnect, se); se->initialized = true; return ENGINE_SUCCESS; }
static PyObject* read_vis(PyObject* self, PyObject* args) { oskar_MeasurementSet* h = 0; PyObject *capsule = 0; PyArrayObject *vis = 0; npy_intp dims[3]; int start_row = 0, num_baselines = 0; int start_channel = 0, num_channels = 0, status = 0; const char* column_name = 0; if (!PyArg_ParseTuple(args, "Oiiiis", &capsule, &start_row, &start_channel, &num_channels, &num_baselines, &column_name)) return 0; if (!(h = get_handle(capsule))) return 0; /* Create numpy array to return. */ dims[0] = num_channels; dims[1] = num_baselines; dims[2] = oskar_ms_num_pols(h); vis = (PyArrayObject*)PyArray_SimpleNew(3, dims, NPY_CFLOAT); /* Allow threads. */ Py_BEGIN_ALLOW_THREADS /* Read the visibility data. */ oskar_ms_read_vis_f(h, start_row, start_channel, num_channels, num_baselines, column_name, (float*)PyArray_DATA(vis), &status); /* Disallow threads. */ Py_END_ALLOW_THREADS /* Check for errors. */ if (status) { PyErr_Format(PyExc_RuntimeError, "oskar_ms_read_vis() failed with code %d.", status); Py_XDECREF(vis); return 0; } /* Return the data. */ return Py_BuildValue("N", vis); /* Don't increment refcount. */ }
END_TEST START_TEST (test_handle) { OMX_ERRORTYPE omx_error; OMX_HANDLETYPE omx_handle; omx_error = init (); fail_if (omx_error != OMX_ErrorNone); omx_error = get_handle (&omx_handle, "OMX.check.dummy", NULL, NULL); fail_if (omx_error != OMX_ErrorNone); omx_error = free_handle (omx_handle); fail_if (omx_error != OMX_ErrorNone); omx_error = deinit (); fail_if (omx_error != OMX_ErrorNone); }
static void process_write(u_int32_t id) { u_int64_t off; size_t len; int r, handle, fd, ret, status; u_char *data; if ((r = get_handle(iqueue, &handle)) != 0 || (r = sshbuf_get_u64(iqueue, &off)) != 0 || (r = sshbuf_get_string(iqueue, &data, &len)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); debug("request %u: write \"%s\" (handle %d) off %llu len %zu", id, handle_to_name(handle), handle, (unsigned long long)off, len); fd = handle_to_fd(handle); if (fd < 0) status = SSH2_FX_FAILURE; else { if (!(handle_to_flags(handle) & O_APPEND) && lseek(fd, off, SEEK_SET) < 0) { status = errno_to_portable(errno); error("process_write: seek failed"); } else { /* XXX ATOMICIO ? */ ret = write(fd, data, len); if (ret < 0) { error("process_write: write failed"); status = errno_to_portable(errno); } else if ((size_t)ret == len) { status = SSH2_FX_OK; handle_update_write(handle, ret); } else { debug2("nothing at all written"); status = SSH2_FX_FAILURE; } } } send_status(id, status); free(data); }
int PacketHandler::open(void*){ //Save the handle for now ACE_HANDLE handle = get_handle(); //Print a message std::cout << "New session " << handle << " created!" << std::endl; //Register the service handler with the reactor ACE_Reactor::instance()->register_handler(this, ACE_Event_Handler::READ_MASK); //Add new session to the session manager SESSIONMGR::instance()->addSession(handle); //Save the session for now SESSION session = SESSIONMGR::instance()->getSession(handle); //Set the session's objects with the information we have session->socket.setSocket(peer_); //Prepare & send welcome packet Packet welcomePacket; welcomePacket.add<CMD>(PCKT_R_WELCOME); session->socket.write(welcomePacket); //Keep yourself registered with the reactor return 0; }
void master_service::proc_on_init() { rpc_stats_init(); // get aio_handle from master_aio acl::aio_handle* handle = get_handle(); assert(handle != NULL); // init rpc service rpc_manager::get_instance().init(handle, var_cfg_nthreads_limit, var_cfg_rpc_addr); // start one timer to logger the rpc status rpc_timer* timer = new rpc_timer(*handle); timer->start(var_cfg_rpc_timer_interval); __conn_manager = new acl::http_request_manager(); __conn_manager->set_ssl(&ssl_conf); __conn_manager->init(var_cfg_backend_addr, var_cfg_backend_addr, var_cfg_max_conns, var_cfg_conn_timeout, var_cfg_rw_timeout); }
struct shim_msg_handle * get_msg_handle_by_id (IDTYPE msqid) { struct hlist_head * qid_head = &msgq_qid_hlist[MSGQ_HASH(msqid)]; struct shim_msg_handle * tmp, * found = NULL; struct hlist_node * pos; lock(msgq_list_lock); hlist_for_each_entry(tmp, pos, qid_head, qid_hlist) if (tmp->msqid == msqid) { found = tmp; break; } if (found) get_handle(MSG_TO_HANDLE(found)); unlock(msgq_list_lock); return found; }
Socket::Status Socket::receive(void* buffer, uint32 size, uint32& received) { received = 0; if (!buffer) { return STATUS_ERROR; } // receive a chunk of bytes int32 size_received = recv(get_handle(), static_cast<char*>(buffer), static_cast<int32>(size), 0); // check the number of bytes received if (size_received > 0) { received = static_cast<uint32>(size_received); return STATUS_DONE; } else if (size_received == 0) { return STATUS_DISCONNECTED; } else { return priv::SocketImpl::get_error(); } }
static ENGINE_ERROR_CODE mock_arithmetic(ENGINE_HANDLE* handle, const void* cookie, const void* key, const int nkey, const bool increment, const bool create, const uint64_t delta, const uint64_t initial, const int flags, const rel_time_t exptime, uint64_t *cas, uint64_t *result, uint16_t vbucket) { struct mock_engine *me = get_handle(handle); struct mock_connstruct *c = (void*)cookie; if (c == NULL) { c = (void*)create_mock_cookie(); } c->nblocks = 0; ENGINE_ERROR_CODE ret = ENGINE_SUCCESS; pthread_mutex_lock(&c->mutex); while (ret == ENGINE_SUCCESS && (ret = me->the_engine->arithmetic((ENGINE_HANDLE*)me->the_engine, c, key, nkey, increment, create, delta, initial, flags, exptime, cas, result, vbucket)) == ENGINE_EWOULDBLOCK && c->handle_ewouldblock) { ++c->nblocks; pthread_cond_wait(&c->cond, &c->mutex); ret = c->status; } pthread_mutex_unlock(&c->mutex); if (c != cookie) { destroy_mock_cookie(c); } return ret; }
static void process_write(u_int32_t id) { u_int64_t off; u_int len; int handle, fd, ret, status; char *data; handle = get_handle(); off = get_int64(); data = get_string(&len); debug("request %u: write \"%s\" (handle %d) off %llu len %d", id, handle_to_name(handle), handle, (unsigned long long)off, len); fd = handle_to_fd(handle); if (fd < 0) status = SSH2_FX_FAILURE; else { if (!(handle_to_flags(handle) & O_APPEND) && lseek(fd, off, SEEK_SET) < 0) { status = errno_to_portable(errno); error("process_write: seek failed"); } else { /* XXX ATOMICIO ? */ ret = write(fd, data, len); if (ret < 0) { error("process_write: write failed"); status = errno_to_portable(errno); } else if ((size_t)ret == len) { status = SSH2_FX_OK; handle_update_write(handle, ret); } else { debug2("nothing at all written"); status = SSH2_FX_FAILURE; } } } send_status(id, status); free(data); }
int kqt_Handle_set_data( kqt_Handle handle, const char* key, const void* data, long length) { check_handle(handle, 0); Handle* h = get_handle(handle); check_data_is_valid(h, 0); check_key(h, key, 0); // Short-circuit if we have already got invalid data // TODO: Remove this if we decide to collect more error info if (Error_is_set(&h->validation_error)) return 1; if (length < 0) { Handle_set_error( h, ERROR_ARGUMENT, "Data length must be non-negative"); return 0; } if (data == NULL && length > 0) { Handle_set_error( h, ERROR_ARGUMENT, "Data must not be null if given length (%ld) is positive", length); return 0; } if (!parse_data(h, key, data, length)) return 0; h->data_is_validated = false; return 1; }
static PyObject * py_hivex_root (PyObject *self, PyObject *args) { PyObject *py_r; hive_node_h r; hive_h *h; PyObject *py_h; if (!PyArg_ParseTuple (args, (char *) "O:hivex_root", &py_h)) return NULL; h = get_handle (py_h); r = hivex_root (h); if (r == 0) { PyErr_SetString (PyExc_RuntimeError, strerror (errno)); return NULL; } py_r = PyLong_FromLongLong (r); return py_r; }
static void do_open (void) { char *from, *handle; MateVFSHandle *from_handle; MateVFSResult result; handle = get_handle (); from = get_fname (); if (!handle || !from) { fprintf (vfserr, "open <handle> <filename>\n"); return; } result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ); if (show_if_error (result, "open ", from)) return; register_file (handle, from_handle); }
struct shim_msg_handle * get_msg_handle_by_key (unsigned long key) { struct hlist_head * key_head = &msgq_key_hlist[MSGQ_HASH(key)]; struct shim_msg_handle * tmp, * found = NULL; struct hlist_node * pos; lock(msgq_list_lock); hlist_for_each_entry(tmp, pos, key_head, key_hlist) if (tmp->msqkey == key) { found = tmp; break; } if (found) get_handle(MSG_TO_HANDLE(found)); unlock(msgq_list_lock); return found; }
static void do_handleinfo (void) { const char *handlename = get_handle (); MateVFSResult result; MateVFSHandle *handle = lookup_file (handlename); MateVFSFileInfo *info; if (!handle) return; info = mate_vfs_file_info_new (); result = mate_vfs_get_file_info_from_handle (handle, info, MATE_VFS_FILE_INFO_GET_MIME_TYPE); if (show_if_error (result, "getting info from handle: ", handlename)) return; print_info (info); mate_vfs_file_info_unref (info); }
int PacketHandler::open(void*){ //Save the handle for now ACE_HANDLE handle = get_handle(); //Print a message std::cout << "New client " << handle << " joined!" << std::endl; //Register the service handler with the reactor ACE_Reactor::instance()->register_handler(this, ACE_Event_Handler::READ_MASK); //Add new session to the session manager SESSIONMGR::instance()->addSession(handle); //Save the session for now SESSION session = SESSIONMGR::instance()->getSession(handle); //Prepare the session' objects with the information we already have. //Here we don't test the pointer because it was just created; Therefore, we knows it is valid. session->socket.setSocket(peer_); //Prepare & send welcome packet Packet welcomePacket; welcomePacket.add<CMD>(PCKT_W_WELCOME); session->socket.write(welcomePacket); //Keep yourself registered with the reactor return 0; }
int WorldSocket::Update (void) { if (closing_) return -1; if (m_OutActive) return 0; { ACE_GUARD_RETURN(LockType, Guard, m_OutBufferLock, 0); if (m_OutBuffer->length() == 0 && msg_queue()->is_empty()) return 0; } int ret; do ret = handle_output(get_handle()); while (ret > 0); return ret; }
static PyObject* read_coords(PyObject* self, PyObject* args) { oskar_MeasurementSet* h = 0; PyObject *capsule = 0, *tuple = 0; PyArrayObject *uu = 0, *vv = 0, *ww = 0; npy_intp dims[1]; int start_row = 0, num_rows = 0, status = 0; if (!PyArg_ParseTuple(args, "Oii", &capsule, &start_row, &num_rows)) return 0; if (!(h = (oskar_MeasurementSet*) get_handle(capsule, name))) return 0; /* Create numpy arrays to return. */ dims[0] = num_rows; uu = (PyArrayObject*)PyArray_SimpleNew(1, dims, NPY_DOUBLE); vv = (PyArrayObject*)PyArray_SimpleNew(1, dims, NPY_DOUBLE); ww = (PyArrayObject*)PyArray_SimpleNew(1, dims, NPY_DOUBLE); /* Read the coordinates. */ Py_BEGIN_ALLOW_THREADS oskar_ms_read_coords_d(h, start_row, num_rows, (double*)PyArray_DATA(uu), (double*)PyArray_DATA(vv), (double*)PyArray_DATA(ww), &status); Py_END_ALLOW_THREADS /* Check for errors. */ if (status) { PyErr_Format(PyExc_RuntimeError, "oskar_ms_read_coords() failed with code %d.", status); Py_XDECREF(uu); Py_XDECREF(vv); Py_XDECREF(ww); return 0; } /* Return a tuple of the coordinates. */ tuple = PyTuple_Pack(3, uu, vv, ww); return Py_BuildValue("N", tuple); /* Don't increment refcount. */ }
static void process_read(void) { char buf[64*1024]; u_int32_t id, len; int handle, fd, ret, status = SSH2_FX_FAILURE; u_int64_t off; id = get_int(); handle = get_handle(); off = get_int64(); len = get_int(); debug("request %u: read \"%s\" (handle %d) off %llu len %d", id, handle_to_name(handle), handle, (unsigned long long)off, len); if (len > sizeof buf) { len = sizeof buf; debug2("read change len %d", len); } fd = handle_to_fd(handle); if (fd >= 0) { if (lseek(fd, off, SEEK_SET) < 0) { error("process_read: seek failed"); status = errno_to_portable(errno); } else { ret = read(fd, buf, len); if (ret < 0) { status = errno_to_portable(errno); } else if (ret == 0) { status = SSH2_FX_EOF; } else { send_data(id, buf, ret); status = SSH2_FX_OK; handle_update_read(handle, ret); } } } if (status != SSH2_FX_OK) send_status(id, status); }
int kqt_Handle_fire_event(kqt_Handle handle, int channel, const char* event) { check_handle(handle, 0); Handle* h = get_handle(handle); check_data_is_valid(h, 0); check_data_is_validated(h, 0); if (channel < 0 || channel >= KQT_COLUMNS_MAX) { Handle_set_error(h, ERROR_ARGUMENT, "Invalid channel number: %d", channel); return 0; } if (event == NULL) { Handle_set_error(h, ERROR_ARGUMENT, "No event description given"); return 0; } const size_t length = strlen(event); if (length > 4096) { Handle_set_error(h, ERROR_ARGUMENT, "Event description is too long"); return 0; } Streader* sr = Streader_init(STREADER_AUTO, event, (int64_t)length); if (!Player_fire(h->player, channel, sr)) { rassert(Streader_is_error_set(sr)); Handle_set_error( h, ERROR_ARGUMENT, "Invalid event description `%s`: %s", event, Streader_get_error_desc(sr)); return 0; } return 1; }
static void process_read(u_int32_t id) { u_char buf[64*1024]; u_int32_t len; int r, handle, fd, ret, status = SSH2_FX_FAILURE; u_int64_t off; if ((r = get_handle(iqueue, &handle)) != 0 || (r = sshbuf_get_u64(iqueue, &off)) != 0 || (r = sshbuf_get_u32(iqueue, &len)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); debug("request %u: read \"%s\" (handle %d) off %llu len %d", id, handle_to_name(handle), handle, (unsigned long long)off, len); if (len > sizeof buf) { len = sizeof buf; debug2("read change len %d", len); } fd = handle_to_fd(handle); if (fd >= 0) { if (lseek(fd, off, SEEK_SET) < 0) { error("process_read: seek failed"); status = errno_to_portable(errno); } else { ret = read(fd, buf, len); if (ret < 0) { status = errno_to_portable(errno); } else if (ret == 0) { status = SSH2_FX_EOF; } else { send_data(id, buf, ret); status = SSH2_FX_OK; handle_update_read(handle, ret); } } } if (status != SSH2_FX_OK) send_status(id, status); }
static PyObject* save(PyObject* self, PyObject* args) { oskar_Sky *h = 0; PyObject* capsule = 0; int status = 0; const char* filename = 0; if (!PyArg_ParseTuple(args, "Os", &capsule, &filename)) return 0; if (!(h = get_handle(capsule))) return 0; /* Save the sky model. */ oskar_sky_save(filename, h, &status); /* Check for errors. */ if (status) { PyErr_Format(PyExc_RuntimeError, "oskar_sky_save() failed with code %d (%s).", status, oskar_get_error_string(status)); return 0; } return Py_BuildValue(""); }
void OpenDDS::DCPS::TcpSendStrategy::schedule_output() { DBG_ENTRY_LVL("TcpSendStrategy","schedule_output",6); // Notify the reactor to adjust its processing policy according to mode_. synch()->work_available(); if (DCPS_debug_level > 4) { const char* action = ""; if( mode() == MODE_DIRECT) { action = "canceling"; } else if( (mode() == MODE_QUEUE) || (mode() == MODE_SUSPEND)) { action = "starting"; } ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) TcpSendStrategy::schedule_output() [%d] - ") ACE_TEXT("%C data queueing for handle %d.\n"), id(),action,get_handle())); } }
static ERL_NIF_TERM cdbwriter_add( ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { cdbwriter_handle* handle = get_handle(env, argv[0]); if(!handle || (handle->fd < 0)) return enif_make_atom(env, "invalid_handle"); int key_len; char * key = get_str(env, argv[1], &key_len); int val_len; if(!key) return enif_make_atom(env, "invalid_key"); char * val = get_str(env, argv[2], &val_len); if(!val) return enif_make_atom(env, "invalid_val"); int fres = cdb_make_add(&(handle->cdbm), key, key_len, val, val_len); free(key); free(val); if(fres!=0) return enif_make_atom(env, "failed_add"); return enif_make_atom(env, "ok"); }
static PyObject * py_hivex_value_struct_length (PyObject *self, PyObject *args) { PyObject *py_r; size_t r; hive_h *h; PyObject *py_h; long val; if (!PyArg_ParseTuple (args, (char *) "Ol:hivex_value_struct_length", &py_h, &val)) return NULL; h = get_handle (py_h); r = hivex_value_struct_length (h, val); if (r == 0) { PyErr_SetString (PyExc_RuntimeError, strerror (errno)); return NULL; } py_r = PyLong_FromLongLong (r); return py_r; }
static void process_read(void) { char buf[64*1024]; u_int32_t id, len; int handle, fd, ret, status = SSH2_FX_FAILURE; u_int64_t off; id = get_int(); handle = get_handle(); off = get_int64(); len = get_int(); TRACE("read id %u handle %d off %llu len %d", id, handle, (u_int64_t)off, len); if (len > sizeof buf) { len = sizeof buf; log("read change len %d", len); } fd = handle_to_fd(handle); if (fd >= 0) { if (lseek(fd, off, SEEK_SET) < 0) { error("process_read: seek failed"); status = errno_to_portable(errno); } else { ret = read(fd, buf, len); if (ret < 0) { status = errno_to_portable(errno); } else if (ret == 0) { status = SSH2_FX_EOF; } else { send_data(id, buf, ret); status = SSH2_FX_OK; } } } if (status != SSH2_FX_OK) send_status(id, status); }
static PyObject * py_hivex_close (PyObject *self, PyObject *args) { PyObject *py_r; int r; hive_h *h; PyObject *py_h; if (!PyArg_ParseTuple (args, (char *) "O:hivex_close", &py_h)) return NULL; h = get_handle (py_h); r = hivex_close (h); if (r == -1) { PyErr_SetString (PyExc_RuntimeError, strerror (errno)); return NULL; } Py_INCREF (Py_None); py_r = Py_None; return py_r; }
/* return the old flags (or -1 on error) */ static int set_handle_flags( struct process *process, obj_handle_t handle, int mask, int flags ) { struct handle_entry *entry; unsigned int old_access; if (get_magic_handle( handle )) { /* we can retrieve but not set info for magic handles */ if (mask) set_error( STATUS_ACCESS_DENIED ); return 0; } if (!(entry = get_handle( process, handle ))) { set_error( STATUS_INVALID_HANDLE ); return -1; } old_access = entry->access; mask = (mask << RESERVED_SHIFT) & RESERVED_ALL; flags = (flags << RESERVED_SHIFT) & mask; entry->access = (entry->access & ~mask) | flags; return (old_access & RESERVED_ALL) >> RESERVED_SHIFT; }
static PyObject * py_hivex_last_modified (PyObject *self, PyObject *args) { PyObject *py_r; errno = 0; int64_t r; hive_h *h; PyObject *py_h; if (!PyArg_ParseTuple (args, (char *) "O:hivex_last_modified", &py_h)) return NULL; h = get_handle (py_h); r = hivex_last_modified (h); if (r == -1 && errno != 0) { PyErr_SetString (PyExc_RuntimeError, strerror (errno)); return NULL; } py_r = PyLong_FromLongLong (r); return py_r; }