本文整理汇总了C++中enter_blocking_section函数的典型用法代码示例。如果您正苦于以下问题:C++ enter_blocking_section函数的具体用法?C++ enter_blocking_section怎么用?C++ enter_blocking_section使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enter_blocking_section函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unix_read
CAMLprim value unix_read(value fd, value buf, value ofs, value vlen)
{
intnat len;
DWORD numbytes, numread;
char iobuf[UNIX_BUFFER_SIZE];
DWORD err = 0;
Begin_root (buf);
len = Long_val(vlen);
numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len;
if (Descr_kind_val(fd) == KIND_SOCKET) {
int ret;
SOCKET s = Socket_val(fd);
enter_blocking_section();
ret = recv(s, iobuf, numbytes, 0);
if (ret == SOCKET_ERROR) err = WSAGetLastError();
leave_blocking_section();
numread = ret;
} else {
HANDLE h = Handle_val(fd);
enter_blocking_section();
if (! ReadFile(h, iobuf, numbytes, &numread, NULL))
err = GetLastError();
leave_blocking_section();
}
if (err) {
win32_maperr(err);
uerror("read", Nothing);
}
memmove (&Byte(buf, Long_val(ofs)), iobuf, numread);
End_roots();
return Val_int(numread);
}
示例2: unix_gethostbyaddr
CAMLprim value unix_gethostbyaddr(value a)
{
struct in_addr adr = GET_INET_ADDR(a);
struct hostent * hp;
#if HAS_GETHOSTBYADDR_R == 7
struct hostent h;
char buffer[NETDB_BUFFER_SIZE];
int h_errnop;
enter_blocking_section();
hp = gethostbyaddr_r((char *) &adr, 4, AF_INET,
&h, buffer, sizeof(buffer), &h_errnop);
leave_blocking_section();
#elif HAS_GETHOSTBYADDR_R == 8
struct hostent h;
char buffer[NETDB_BUFFER_SIZE];
int h_errnop, rc;
enter_blocking_section();
rc = gethostbyaddr_r((char *) &adr, 4, AF_INET,
&h, buffer, sizeof(buffer), &hp, &h_errnop);
leave_blocking_section();
if (rc != 0) hp = NULL;
#else
#ifdef GETHOSTBYADDR_IS_REENTRANT
enter_blocking_section();
#endif
hp = gethostbyaddr((char *) &adr, 4, AF_INET);
#ifdef GETHOSTBYADDR_IS_REENTRANT
leave_blocking_section();
#endif
#endif
if (hp == (struct hostent *) NULL) raise_not_found();
return alloc_host_entry(hp);
}
示例3: unix_gethostbyname
CAMLprim value unix_gethostbyname(value name)
{
struct hostent * hp;
char * hostname;
#if HAS_GETHOSTBYNAME_R
struct hostent h;
char buffer[NETDB_BUFFER_SIZE];
int err;
#endif
if (! caml_string_is_c_safe(name)) raise_not_found();
#if HAS_GETHOSTBYNAME_R || GETHOSTBYNAME_IS_REENTRANT
hostname = caml_strdup(String_val(name));
#else
hostname = String_val(name);
#endif
#if HAS_GETHOSTBYNAME_R == 5
{
enter_blocking_section();
hp = gethostbyname_r(hostname, &h, buffer, sizeof(buffer), &err);
leave_blocking_section();
}
#elif HAS_GETHOSTBYNAME_R == 6
{
int rc;
enter_blocking_section();
rc = gethostbyname_r(hostname, &h, buffer, sizeof(buffer), &hp, &err);
leave_blocking_section();
if (rc != 0) hp = NULL;
}
#else
#ifdef GETHOSTBYNAME_IS_REENTRANT
enter_blocking_section();
#endif
hp = gethostbyname(hostname);
#ifdef GETHOSTBYNAME_IS_REENTRANT
leave_blocking_section();
#endif
#endif
#if HAS_GETHOSTBYNAME_R || GETHOSTBYNAME_IS_REENTRANT
stat_free(hostname);
#endif
if (hp == (struct hostent *) NULL) raise_not_found();
return alloc_host_entry(hp);
}
示例4: unix_recv
CAMLprim value unix_recv(value sock, value buff, value ofs, value len,
value flags)
{
SOCKET s = Socket_val(sock);
int flg = convert_flag_list(flags, msg_flag_table);
int ret;
intnat numbytes;
char iobuf[UNIX_BUFFER_SIZE];
DWORD err = 0;
Begin_root (buff);
numbytes = Long_val(len);
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
enter_blocking_section();
ret = recv(s, iobuf, (int) numbytes, flg);
if (ret == -1) err = WSAGetLastError();
leave_blocking_section();
if (ret == -1) {
win32_maperr(err);
uerror("recv", Nothing);
}
memmove (&Byte(buff, Long_val(ofs)), iobuf, ret);
End_roots();
return Val_int(ret);
}
示例5: unix_write
CAMLprim value unix_write(value fd, value buf, value vofs, value vlen)
{
long ofs, len, written;
int numbytes, ret;
char iobuf[UNIX_BUFFER_SIZE];
Begin_root (buf);
ofs = Long_val(vofs);
len = Long_val(vlen);
written = 0;
while (len > 0) {
numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len;
memmove (iobuf, &Byte(buf, ofs), numbytes);
enter_blocking_section();
ret = write(Int_val(fd), iobuf, numbytes);
leave_blocking_section();
if (ret == -1) {
if ((errno == EAGAIN || errno == EWOULDBLOCK) && written > 0) break;
uerror("write", Nothing);
}
written += ret;
ofs += ret;
len -= ret;
}
End_roots();
return Val_long(written);
}
示例6: unix_recvfrom
CAMLprim value unix_recvfrom(value sock, value buff, value ofs, value len,
value flags)
{
int ret, cv_flags;
long numbytes;
char iobuf[UNIX_BUFFER_SIZE];
value res;
value adr = Val_unit;
union sock_addr_union addr;
socklen_param_type addr_len;
cv_flags = convert_flag_list(flags, msg_flag_table);
Begin_roots2 (buff, adr);
numbytes = Long_val(len);
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
addr_len = sizeof(addr);
enter_blocking_section();
ret = recvfrom(Int_val(sock), iobuf, (int) numbytes, cv_flags,
&addr.s_gen, &addr_len);
leave_blocking_section();
if (ret == -1) uerror("recvfrom", Nothing);
memmove (&Byte(buff, Long_val(ofs)), iobuf, ret);
adr = alloc_sockaddr(&addr, addr_len, -1);
res = alloc_small(2, 0);
Field(res, 0) = Val_int(ret);
Field(res, 1) = adr;
End_roots();
return res;
}
示例7: ml_ip_job_start
value ml_ip_job_start(value job_v)
{
strcpy( (char*) job_hostname, String_val(Field(job_v,0)));
if(!thread_started){
int retcode;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_cond_init(&cond, NULL);
pthread_mutex_init(&mutex, NULL);
thread_started = 1;
retcode = pthread_create(&pthread, &attr, hasher_thread, NULL);
if(retcode){
perror("Error while starting Hashing thread");
exit(2);
}
}
enter_blocking_section();
pthread_mutex_lock(&mutex);
/* printf("Starting job\n"); */
ip_job_done = 0; /* Thread can run ... */
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
leave_blocking_section ();
return Val_unit;
}
示例8: win_waitpid
CAMLprim value win_waitpid(value vflags, value vpid_req)
{
int flags;
DWORD status, retcode;
HANDLE pid_req = (HANDLE) Long_val(vpid_req);
DWORD err = 0;
flags = convert_flag_list(vflags, wait_flag_table);
if ((flags & CAML_WNOHANG) == 0) {
enter_blocking_section();
retcode = WaitForSingleObject(pid_req, INFINITE);
if (retcode == WAIT_FAILED) err = GetLastError();
leave_blocking_section();
if (err) {
win32_maperr(err);
uerror("waitpid", Nothing);
}
}
if (! GetExitCodeProcess(pid_req, &status)) {
win32_maperr(GetLastError());
uerror("waitpid", Nothing);
}
if (status == STILL_ACTIVE)
return alloc_process_status((HANDLE) 0, 0);
else {
CloseHandle(pid_req);
return alloc_process_status(pid_req, status);
}
}
示例9: worker_job_submit
LPWORKER worker_job_submit (WORKERFUNC f, void *user_data)
{
LPWORKER lpWorker = worker_pop();
#ifdef DBUG
dbug_print("Waiting for worker to be ready");
#endif
enter_blocking_section();
WaitForSingleObject(lpWorker->hWorkerReady, INFINITE);
ResetEvent(lpWorker->hWorkerReady);
leave_blocking_section();
#ifdef DBUG
dbug_print("Worker is ready");
#endif
lpWorker->hJobFunc = f;
lpWorker->lpJobUserData = user_data;
lpWorker->ECommand = WORKER_CMD_EXEC;
#ifdef DBUG
dbug_print("Call worker (func: %x, worker: %x)", f, lpWorker);
#endif
SetEvent(lpWorker->hCommandReady);
return (LPWORKER)lpWorker;
}
示例10: unix_recvfrom
CAMLprim value unix_recvfrom(value sock, value buff, value ofs, value len, value flags)
{
SOCKET s = Socket_val(sock);
int flg = convert_flag_list(flags, msg_flag_table);
int ret;
intnat numbytes;
char iobuf[UNIX_BUFFER_SIZE];
value res;
value adr = Val_unit;
union sock_addr_union addr;
socklen_param_type addr_len;
DWORD err = 0;
Begin_roots2 (buff, adr);
numbytes = Long_val(len);
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
addr_len = sizeof(sock_addr);
enter_blocking_section();
ret = recvfrom(s, iobuf, (int) numbytes, flg, &addr.s_gen, &addr_len);
if (ret == -1) err = WSAGetLastError();
leave_blocking_section();
if (ret == -1) {
win32_maperr(err);
uerror("recvfrom", Nothing);
}
memmove (&Byte(buff, Long_val(ofs)), iobuf, ret);
adr = alloc_sockaddr(&addr, addr_len, -1);
res = alloc_small(2, 0);
Field(res, 0) = Val_int(ret);
Field(res, 1) = adr;
End_roots();
return res;
}
示例11: stub_sendfile64
CAMLprim value stub_sendfile64(value in_fd, value out_fd, value len){
CAMLparam3(in_fd, out_fd, len);
CAMLlocal1(result);
size_t c_len = Int64_val(len);
size_t bytes;
int c_in_fd = Int_val(in_fd);
int c_out_fd = Int_val(out_fd);
int rc = NOT_IMPLEMENTED;
enter_blocking_section();
#ifdef __linux__
rc = TRIED_AND_FAILED;
bytes = sendfile(c_out_fd, c_in_fd, NULL, c_len);
if (bytes != -1) rc = OK;
#endif
leave_blocking_section();
switch (rc) {
case NOT_IMPLEMENTED:
caml_failwith("This platform does not support sendfile()");
break;
case TRIED_AND_FAILED:
uerror("sendfile", Nothing);
break;
default: break;
}
result = caml_copy_int64(bytes);
CAMLreturn(result);
}
示例12: unix_getnameinfo
CAMLprim value unix_getnameinfo(value vaddr, value vopts)
{
CAMLparam0();
CAMLlocal3(vhost, vserv, vres);
union sock_addr_union addr;
socklen_param_type addr_len;
char host[4096];
char serv[1024];
int opts, retcode;
get_sockaddr(vaddr, &addr, &addr_len);
opts = convert_flag_list(vopts, getnameinfo_flag_table);
enter_blocking_section();
retcode =
getnameinfo((const struct sockaddr *) &addr.s_gen, addr_len,
host, sizeof(host), serv, sizeof(serv), opts);
leave_blocking_section();
if (retcode != 0) raise_not_found(); /* TODO: detailed error reporting? */
vhost = copy_string(host);
vserv = copy_string(serv);
vres = alloc_small(2, 0);
Field(vres, 0) = vhost;
Field(vres, 1) = vserv;
CAMLreturn(vres);
}
示例13: unix_sleep
CAMLprim value unix_sleep(value t)
{
enter_blocking_section();
sleep(Int_val(t));
leave_blocking_section();
return Val_unit;
}
示例14: unix_sendto_native
value unix_sendto_native(value sock, value buff, value ofs, value len, value flags, value dest)
{
SOCKET s = Socket_val(sock);
int flg = convert_flag_list(flags, msg_flag_table);
int ret;
intnat numbytes;
char iobuf[UNIX_BUFFER_SIZE];
union sock_addr_union addr;
socklen_param_type addr_len;
DWORD err = 0;
get_sockaddr(dest, &addr, &addr_len);
numbytes = Long_val(len);
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes);
enter_blocking_section();
ret = sendto(s, iobuf, (int) numbytes, flg, &addr.s_gen, addr_len);
if (ret == -1) err = WSAGetLastError();
leave_blocking_section();
if (ret == -1) {
win32_maperr(err);
uerror("sendto", Nothing);
}
return Val_int(ret);
}
示例15: caml_thread_delay
CAMLprim value caml_thread_delay(value val)
{
enter_blocking_section();
Sleep((DWORD)(Double_val(val)*1000)); /* milliseconds */
leave_blocking_section();
return Val_unit;
}