本文整理汇总了C++中HANDLE函数的典型用法代码示例。如果您正苦于以下问题:C++ HANDLE函数的具体用法?C++ HANDLE怎么用?C++ HANDLE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HANDLE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteThreadProc
DWORD WINAPI WriteThreadProc(LPVOID lpParameter)
{
HANDLE hFile = HANDLE(lpParameter);
do
{
WriteBuffer* write_buffer = NULL;
bool exit = false;
EnterCriticalSection(&g_write_queue_cs);
if (g_write_queue.size() > 0)
{
write_buffer = g_write_queue.front();
g_write_queue.pop();
g_total_bytes_written += write_buffer->useful_data_size_;
}
else if (g_done)
{
exit = true;
}
SetEvent(g_write_queue_accepts_more_data_event);
LeaveCriticalSection(&g_write_queue_cs);
if (write_buffer)
{
/* DWORD bytes_written = 0;
::WriteFile(hFile, write_buffer->ptr_, write_buffer->useful_data_size_,
&bytes_written, NULL); */
delete write_buffer;
}
else if (exit) {
break;
} else {
// Wait for new(s).
WaitForSingleObject(g_write_queue_has_more_data_event, INFINITE);
}
} while (true);
return 1;
}
示例2: pnm_load
pnm
pnm_load(char *path)
{
FILE *input = L_r_open(path);
pnm self = NULL;
HANDLE(any, self = L_load(input));
fclose(input);
if (EXCEPTION_RAISED(any))
{
if (self != NULL)
memory_free(self);
if (EXCEPTION_RAISED(get_int))
RAISE(error, "Truncated pnm file");
if (EXCEPTION_RAISED(any))
RAISE_AGAIN();
}
return self;
}
示例3: on_timer_callback
static void
on_timer_callback(uv_timer_t *handle)
{
PyGILState_STATE gstate = PyGILState_Ensure();
Timer *self;
PyObject *result;
ASSERT(handle);
self = PYUV_CONTAINER_OF(handle, Timer, timer_h);
/* Object could go out of scope in the callback, increase refcount to avoid it */
Py_INCREF(self);
result = PyObject_CallFunctionObjArgs(self->callback, self, NULL);
if (result == NULL) {
handle_uncaught_exception(HANDLE(self)->loop);
}
Py_XDECREF(result);
Py_DECREF(self);
PyGILState_Release(gstate);
}
示例4: on_pipe_read2
static void
on_pipe_read2(uv_pipe_t* handle, int nread, uv_buf_t buf, uv_handle_type pending)
{
PyGILState_STATE gstate = PyGILState_Ensure();
uv_err_t err;
Stream *self;
PyObject *result, *data, *py_errorno, *py_pending;
ASSERT(handle);
self = (Stream *)handle->data;
ASSERT(self);
/* Object could go out of scope in the callback, increase refcount to avoid it */
Py_INCREF(self);
py_pending = PyInt_FromLong((long)pending);
if (nread >= 0) {
data = PyBytes_FromStringAndSize(buf.base, nread);
py_errorno = Py_None;
Py_INCREF(Py_None);
} else {
data = Py_None;
Py_INCREF(Py_None);
err = uv_last_error(UV_HANDLE_LOOP(self));
py_errorno = PyInt_FromLong((long)err.code);
}
result = PyObject_CallFunctionObjArgs(self->on_read_cb, self, data, py_pending, py_errorno, NULL);
if (result == NULL) {
handle_uncaught_exception(HANDLE(self)->loop);
}
Py_XDECREF(result);
Py_DECREF(data);
Py_DECREF(py_pending);
Py_DECREF(py_errorno);
Py_DECREF(self);
PyGILState_Release(gstate);
}
示例5: sizeof
bool SockPool::InitalWriteQueue(HANDLE WriteQueue, PM &pWriteQueue)
{
pWriteQueue = (PM)MapViewOfFile(WriteQueue, FILE_MAP_WRITE, 0, 0, sizeof(Manager));///<映射写队列控制块到本地
if (pWriteQueue == NULL)
return PrintLog(_T("写控制块映射失败"), false);
pWriteQueue->hid = 0; ///<初始化写控制块参数
pWriteQueue->cid = 0;
pWriteQueue->writer = _getpid();
pWriteQueue->Cur = NULL;
HANDLE EmptyNode = CreateFileMapping(HANDLE(0xFFFFFFFF), NULL, PAGE_READWRITE, 0, sizeof(Node), NULL);///<创建一个空节点
PN pNode = (PN)MapViewOfFile(EmptyNode, FILE_MAP_WRITE, 0, 0, sizeof(Node));///<映射节点到本地
memset(pNode, 0, sizeof(Node));
UnmapViewOfFile(pNode);
DuplicateHandle(SH, EmptyNode, SH, &pWriteQueue->Tail, NULL, true, DUPLICATE_SAME_ACCESS); ///<空节点加入链表
DuplicateHandle(SH, EmptyNode, SH, &pWriteQueue->Head, NULL, true, DUPLICATE_SAME_ACCESS);
CloseHandle(EmptyNode);
if (!(pWriteQueue->Tail || pWriteQueue->Head))
return PrintLog(_T("控制管理块初始化失败"), false);
return true;
}
示例6: x4_ike_select_prime
x4s_buf x4_ike_select_prime(uint16 v)
{
x4s_buf r = { 0 };
#define HANDLE(bits) \
case x4c_ike_a1g_modp_##bits : \
x4_buf_attach(&r,x4v_ike_modp##bits,sizeof(x4v_ike_modp##bits)); \
break;
switch (v)
{
HANDLE(768);
HANDLE(1024);
HANDLE(1536);
HANDLE(2048);
HANDLE(3072);
HANDLE(4096);
HANDLE(6144);
HANDLE(8192);
}
return r;
#undef HANDLE
}
示例7: iq_add_handlers
void
iq_add_handlers(void)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, STANZA_TYPE_ERROR, _error_handler);
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _disco_info_get_handler);
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_RESULT, _disco_info_result_handler);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _disco_items_get_handler);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _disco_items_result_handler);
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _version_get_handler);
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _version_result_handler);
HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler);
if (prefs_get_autoping() != 0) {
int millis = prefs_get_autoping() * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx);
}
}
示例8: CloseHandle
void CFile::open(const STRING &fileName, CONST UINT mode)
{
if (m_hFile != HFILE_ERROR)
{
CloseHandle(HANDLE(m_hFile));
}
m_filename = fileName;
DWORD access = GENERIC_READ;
if (mode & OF_WRITE) access |= GENERIC_WRITE;
DWORD creation = (mode & OF_CREATE) ? CREATE_ALWAYS : OPEN_EXISTING;
m_hFile = (HFILE)CreateFile(resolve(fileName).c_str(),
access,
FILE_SHARE_READ,
NULL,
creation,
FILE_ATTRIBUTE_NORMAL,
NULL);
memset(&m_ptr, 0, sizeof(m_ptr));
}
示例9: memcpy
/**
* @author ACM2012
* @param [in] pNode新创建的节点句柄,SockMark套接字唯一标示符
* @note 函数的主要功能是将类中缓存的接收到的数据打包到新创建的节点
*/
bool SockPool::SockDataToNode(PN pNode, unsigned int SockMark)///<将数据打包成节点形式
{
bool tmpflag = true;
transstruct *psockstruct = SockMark2SockStruct[SockMark];
memcpy(pNode->dstip, psockstruct->dstip, 20);///<填充字段
memcpy(pNode->srcip, psockstruct->srcip, 20);
pNode->dstport = psockstruct->dstport;
pNode->srcport = psockstruct->srcport;
pNode->DataLen = psockstruct->datalength;
pNode->FuncID = psockstruct->function;
CString myid;
myid.Format(_T("%d"), pNode->FuncID);
//AfxMessageBox(myid);
if (pNode->FuncID == SOCKSEND || pNode->FuncID == SOCKSENDTO)
pNode->Data = CreateFileMapping(HANDLE(0xFFFFFFFF), NULL, PAGE_READWRITE, 0, pNode->DataLen, NULL);
if (pNode->FuncID == SOCKCLOSE)
tmpflag = false;
void *pData = (void *)MapViewOfFile(pNode->Data, FILE_MAP_WRITE, 0, 0, pNode->DataLen);
if (psockstruct->data!=NULL)
memcpy(pData, psockstruct->data, pNode->DataLen);///<拷贝数据
UnmapViewOfFile(pData);
return tmpflag;
}
示例10: csort
void csort(int *array, int size)
{
/* int tmp[RANGE + 1] = {0}; */
pthread_t *workers[WORKER_THREADS];
args_t *args[WORKER_THREADS];
int chunk_size = size / WORKER_THREADS;
int end = 0;
int i;
/* initialize the tmp array */
for(i = 0; i < RANGE + 1; i++){
sem_init(&tmp[i], 0, 0);
}
/* partition the work */
for(i = 0; i < WORKER_THREADS; i ++){
end = i == WORKER_THREADS - 1 ? size : (i + 1) * chunk_size;
args[i] = make_args(&array, i * chunk_size, end);
workers[i] = malloc(sizeof(pthread_t));
HANDLE(pthread_create(workers[i], NULL, populate_tmp_p, args[i]));
}
/* wait for everything to finish */
for(i = 0; i < WORKER_THREADS; i++){
pthread_join(*workers[i], NULL);
}
/* writeback, sequentially */
unroll_tmp(&array, RANGE);
/* free everything */
// for(i = 0; i < WORKER_THREADS; i++){
// free_args(args[i]);
/* pthread_destroy(workers[i]); */
// }
}
示例11: WriteThreadProc
DWORD WINAPI WriteThreadProc(LPVOID lpParameter)
{
HANDLE hFile = HANDLE(lpParameter);
do
{
WriteBuffer* write_buffer = NULL;
bool exit = false;
EnterCriticalSection(&g_write_queue_cs);
if (g_write_queue.size() > 0)
{
write_buffer = g_write_queue.front();
g_write_queue.pop();
}
else if (g_done)
{
exit = true;
}
LeaveCriticalSection(&g_write_queue_cs);
if (write_buffer)
{
DWORD bytes_written = 0;
::WriteFile(hFile, write_buffer->ptr_, write_buffer->useful_data_size_,
&bytes_written, NULL);
delete write_buffer;
}
else if (exit) {
break;
} else {
::Sleep(0);
}
} while (true);
return 1;
}
示例12: on_pipe_client_connection
static void
on_pipe_client_connection(uv_connect_t *req, int status)
{
PyGILState_STATE gstate = PyGILState_Ensure();
Pipe *self;
PyObject *callback, *result, *py_errorno;
ASSERT(req);
self = (Pipe *)req->handle->data;
callback = (PyObject *)req->data;
ASSERT(self);
if (status != 0) {
uv_err_t err = uv_last_error(UV_HANDLE_LOOP(self));
py_errorno = PyInt_FromLong(err.code);
} else {
py_errorno = Py_None;
Py_INCREF(Py_None);
}
result = PyObject_CallFunctionObjArgs(callback, self, py_errorno, NULL);
if (result == NULL) {
handle_uncaught_exception(HANDLE(self)->loop);
}
Py_XDECREF(result);
Py_DECREF(py_errorno);
Py_DECREF(callback);
PyMem_Free(req);
/* Refcount was increased in the caller function */
Py_DECREF(self);
PyGILState_Release(gstate);
}
示例13: on_check_callback
static void
on_check_callback(uv_check_t *handle, int status)
{
PyGILState_STATE gstate = PyGILState_Ensure();
Check *self;
PyObject *result;
ASSERT(handle);
ASSERT(status == 0);
self = (Check *)handle->data;
ASSERT(self);
/* Object could go out of scope in the callback, increase refcount to avoid it */
Py_INCREF(self);
result = PyObject_CallFunctionObjArgs(self->callback, self, NULL);
if (result == NULL) {
handle_uncaught_exception(HANDLE(self)->loop);
}
Py_XDECREF(result);
Py_DECREF(self);
PyGILState_Release(gstate);
}
示例14: UDP_tp_init
static int
UDP_tp_init(UDP *self, PyObject *args, PyObject *kwargs)
{
int r;
Loop *loop;
UNUSED_ARG(kwargs);
RAISE_IF_HANDLE_INITIALIZED(self, -1);
if (!PyArg_ParseTuple(args, "O!:__init__", &LoopType, &loop)) {
return -1;
}
r = uv_udp_init(loop->uv_loop, (uv_udp_t *)UV_HANDLE(self));
if (r != 0) {
RAISE_UV_EXCEPTION(loop->uv_loop, PyExc_UDPError);
return -1;
}
initialize_handle(HANDLE(self), loop);
return 0;
}
示例15: Timer_tp_init
static int
Timer_tp_init(Timer *self, PyObject *args, PyObject *kwargs)
{
int err;
Loop *loop;
UNUSED_ARG(kwargs);
RAISE_IF_HANDLE_INITIALIZED(self, -1);
if (!PyArg_ParseTuple(args, "O!:__init__", &LoopType, &loop)) {
return -1;
}
err = uv_timer_init(loop->uv_loop, &self->timer_h);
if (err < 0) {
RAISE_UV_EXCEPTION(err, PyExc_TimerError);
return -1;
}
initialize_handle(HANDLE(self), loop);
return 0;
}