当前位置: 首页>>代码示例>>C++>>正文


C++ POSIX_LABEL函数代码示例

本文整理汇总了C++中POSIX_LABEL函数的典型用法代码示例。如果您正苦于以下问题:C++ POSIX_LABEL函数的具体用法?C++ POSIX_LABEL怎么用?C++ POSIX_LABEL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了POSIX_LABEL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: socket_close

/**
	socket_close : 'socket -> void
	<doc>Close a socket. Any subsequent operation on this socket will fail</doc>
**/
static value socket_close( value o ) {
	POSIX_LABEL(close_again);
	if( closesocket(val_sock(o)) ) {
		HANDLE_EINTR(close_again);
	}
	return alloc_bool(true);
}
开发者ID:KTXSoftware,项目名称:Kha-haxelib,代码行数:11,代码来源:Socket.cpp

示例2: file_contents

/**
	file_contents : f:string -> string
	<doc>Read the content of the file [f] and return it.</doc>
**/
static value file_contents( value name ) {
	buffer s;
	int len;
	int p;
	val_check(name,string);
	fio f(val_filename(name));
        const char *fname = val_string(name);
	gc_enter_blocking();
	f.io = fopen(fname,"rb");
	if( f.io == NULL )
		file_error("file_contents",&f);
	fseek(f.io,0,SEEK_END);
	len = ftell(f.io);
	fseek(f.io,0,SEEK_SET);
	gc_exit_blocking();
	s = alloc_buffer_len(len);
	p = 0;
	gc_enter_blocking();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_contents);
		d = (int)fread((char*)buffer_data(s)+p,1,len,f.io);
		if( d <= 0 ) {
			HANDLE_FINTR(f.io,file_contents);
			fclose(f.io);
			file_error("file_contents",&f);
		}
		p += d;
		len -= d;
	}	
	fclose(f.io);
	gc_exit_blocking();
	return buffer_val(s);
}
开发者ID:bjitivo,项目名称:hxcpp,代码行数:38,代码来源:File.cpp

示例3: _hx_std_file_write

/**
   file_write : 'file -> s:string -> p:int -> l:int -> int
   <doc>
   Write up to [l] chars of string [s] starting at position [p]. 
   Returns the number of chars written which is >= 0.
   </doc>
**/
int _hx_std_file_write( Dynamic handle, Array<unsigned char> s, int p, int n )
{
   fio *f = getFio(handle);

   int buflen = s->length;
   int len = n;
   if( p < 0 || len < 0 || p > buflen || p + len > buflen )
      return 0;

   hx::EnterGCFreeZone();
   while( len > 0 )
   {
      POSIX_LABEL(file_write_again);
      int d = (int)fwrite(&s[p],1,len,f->io);
      if( d <= 0 )
      {
         HANDLE_FINTR(f->io,file_write_again);
         file_error("file_write",f->name);
      }
      p += d;
      len -= d;
   }
   hx::ExitGCFreeZone();
   return n;
}
开发者ID:cunwaitaoshu,项目名称:hxcpp,代码行数:32,代码来源:File.cpp

示例4: file_contents

/**
	file_contents : f:string -> string
	<doc>Read the content of the file [f] and return it.</doc>
**/
static value file_contents( value name ) {
	value s;
	fio f;
	int len;
	int p;
	val_check(name,string);
	f.name = name;
	f.io = fopen(val_string(name),"rb");
	if( f.io == NULL )
		file_error("file_contents",&f);
	fseek(f.io,0,SEEK_END);
	len = ftell(f.io);
	fseek(f.io,0,SEEK_SET);
	s = alloc_empty_string(len);
	p = 0;
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_contents);
		d = (int)fread((char*)val_string(s)+p,1,len,f.io);
		if( d <= 0 ) {
			HANDLE_FINTR(f.io,file_contents);
			fclose(f.io);
			file_error("file_contents",&f);
		}
		p += d;
		len -= d;
	}	
	fclose(f.io);
	return s;
}
开发者ID:fantoine,项目名称:haxe-templo2,代码行数:34,代码来源:file.c

示例5: socket_send_to

/**
	socket_send_to : 'socket -> buf:string -> pos:int -> length:int -> addr:{host:'int32,port:int} -> int
	<doc>
	Send data from an unconnected UDP socket to the given address.
	</doc>
**/
static value socket_send_to( value o, value dataBuf, value pos, value len, value vaddr ) {
	int p,l;
	value host, port;
	struct sockaddr_in addr;
	val_check_kind(o,k_socket);
   buffer buf = val_to_buffer(dataBuf);
	const char *cdata = buffer_data(buf);
	int dlen = buffer_size(buf);
	val_check(pos,int);
	val_check(len,int);
	val_check(vaddr,object);
	host = val_field(vaddr, f_host);
	port = val_field(vaddr, f_port);
	val_check(host,int);
	val_check(port,int);
	p = val_int(pos);
	l = val_int(len);
	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(val_int(port));
	*(int*)&addr.sin_addr.s_addr = val_int(host);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();

   SOCKET sock = val_sock(o);
	gc_enter_blocking();
	POSIX_LABEL(send_again);
	dlen = sendto(sock, cdata + p , l, MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr));
	if( dlen == SOCKET_ERROR ) {
		HANDLE_EINTR(send_again);
		return block_error();
	}
	gc_exit_blocking();
	return alloc_int(dlen);
}
开发者ID:CapturaCamera,项目名称:hxcpp,代码行数:41,代码来源:Socket.cpp

示例6: socket_recv_from

static value socket_recv_from( value o, value dataBuf, value pos, value len, value addr ) {
	int p,l,ret;
	int retry = 0;
	struct sockaddr_in saddr;
	SockLen slen = sizeof(saddr);
	val_check_kind(o,k_socket);
	val_check(dataBuf,buffer);
	buffer buf = val_to_buffer(dataBuf);
   char *data = buffer_data(buf);
   int dlen = buffer_size(buf);
	val_check(pos,int);
	val_check(len,int);
	val_check(addr,object);
	p = val_int(pos);
	l = val_int(len);

	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
   SOCKET sock = val_sock(o);
   gc_enter_blocking();
	POSIX_LABEL(recv_from_again);
	if( retry++ > NRETRYS ) {
      ret = recv(sock,data+p,l,MSG_NOSIGNAL);
	} else
		ret = recvfrom(sock, data + p , l, MSG_NOSIGNAL, (struct sockaddr*)&saddr, &slen);
	if( ret == SOCKET_ERROR ) {
		HANDLE_EINTR(recv_from_again);
		return block_error();
	}
   gc_exit_blocking();
	alloc_field(addr,f_host,alloc_int32(*(int*)&saddr.sin_addr));
	alloc_field(addr,f_port,alloc_int(ntohs(saddr.sin_port)));
	return alloc_int(ret);
}
开发者ID:CapturaCamera,项目名称:hxcpp,代码行数:34,代码来源:Socket.cpp

示例7: _hx_std_file_read

/**
   file_read : 'file -> s:string -> p:int -> l:int -> int
   <doc>
   Read up to [l] chars into the string [s] starting at position [p].
   Returns the number of chars readed which is > 0 (or 0 if l == 0).
   </doc>
**/
int _hx_std_file_read( Dynamic handle, Array<unsigned char> buf, int p, int n )
{
   fio *f = getFio(handle);

   int buf_len = buf->length;
   int len = n;
   if( p < 0 || len < 0 || p > buf_len || p + len > buf_len )
      return 0;

   hx::EnterGCFreeZone();
   // Attempt to increase the chances of pinning on the stack...
   unsigned char *bufPtr = &buf[0];
   while( len > 0 )
   {
      POSIX_LABEL(file_read_again);
      int d = (int)fread(bufPtr + p,1,len,f->io);
      if( d <= 0 )
      {
         int size = n - len;
         HANDLE_FINTR(f->io,file_read_again);
         if( size == 0 )
            file_error("file_read",f->name);
         hx::ExitGCFreeZone();
         return size;
      }
      p += d;
      len -= d;
   }
   hx::ExitGCFreeZone();
   return n;
}
开发者ID:cunwaitaoshu,项目名称:hxcpp,代码行数:38,代码来源:File.cpp

示例8: socket_send_to

/**
	socket_send_to : 'socket -> buf:string -> pos:int -> length:int -> addr:{host:'int32,port:int} -> int
	<doc>
	Send data from an unconnected UDP socket to the given address.
	</doc>
**/
static value socket_send_to( value o, value data, value pos, value len, value vaddr ) {
	int p,l,dlen;
	value host, port;
	struct sockaddr_in addr;
	val_check_kind(o,k_socket);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	val_check(vaddr,object);
	host = val_field(vaddr, f_host);
	port = val_field(vaddr, f_port);
	val_check(host,int32);
	val_check(port,int);
	p = val_int(pos);
	l = val_int(len);
	dlen = val_strlen(data);
	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(val_int(port));
	*(int*)&addr.sin_addr.s_addr = val_int32(host);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
	POSIX_LABEL(send_again);
	dlen = sendto(val_sock(o), val_string(data) + p , l, MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr));
	if( dlen == SOCKET_ERROR ) {
		HANDLE_EINTR(send_again);
		return block_error();
	}
	return alloc_int(dlen);
}
开发者ID:motion-twin,项目名称:neko,代码行数:36,代码来源:socket.c

示例9: _hx_std_file_contents_string

/**
   file_contents : f:string -> string
   <doc>Read the content of the file [f] and return it.</doc>
**/
String _hx_std_file_contents_string( String name )
{
   std::vector<char> buffer;

   hx::EnterGCFreeZone();
   FILE *file = fopen(name.__s, "rb");
   if(!file)
      file_error("file_contents",name);

   fseek(file,0,SEEK_END);
   int len = ftell(file);
   if (len<0)
      file_error("file_ftell",name);
   fseek(file,0,SEEK_SET);
   buffer.resize(len);
   int p = 0;
   while( len > 0 )
   {
      POSIX_LABEL(file_contents);
      int d = (int)fread(&buffer[p],1,len,file);
      if( d <= 0 )
      {
         HANDLE_FINTR(file,file_contents);
         fclose(file);
         file_error("file_contents",name);
      }
      p += d;
      len -= d;
   }
   fclose(file);
   hx::ExitGCFreeZone();

   return String(&buffer[0], buffer.size()).dup();
}
开发者ID:cunwaitaoshu,项目名称:hxcpp,代码行数:38,代码来源:File.cpp

示例10: socket_select

/**
	socket_select : read : 'socket array -> write : 'socket array -> others : 'socket array -> timeout:number? -> 'socket array array
	<doc>Perform the [select] operation. Timeout is in seconds or [null] if infinite</doc>
**/
static value socket_select( value rs, value ws, value es, value timeout ) {
	struct timeval tval;
	struct timeval *tt;
	SOCKET n = 0;
	fd_set rx, wx, ex;
	fd_set *ra, *wa, *ea;
	value r;
	POSIX_LABEL(select_again);
	ra = make_socket_array(rs,val_array_size(rs),&rx,&n);
	wa = make_socket_array(ws,val_array_size(ws),&wx,&n);
	ea = make_socket_array(es,val_array_size(es),&ex,&n);
	if( ra == &INVALID || wa == &INVALID || ea == &INVALID )
		neko_error();
	if( val_is_null(timeout) )
		tt = NULL;
	else {
		val_check(timeout,number);
		tt = &tval;
		init_timeval(val_number(timeout),tt);
	}
	if( select((int)(n+1),ra,wa,ea,tt) == SOCKET_ERROR ) {
		HANDLE_EINTR(select_again);
		neko_error();
	}
	r = alloc_array(3);
	val_array_ptr(r)[0] = make_array_result(rs,ra);
	val_array_ptr(r)[1] = make_array_result(ws,wa);
	val_array_ptr(r)[2] = make_array_result(es,ea);
	return r;
}
开发者ID:motion-twin,项目名称:neko,代码行数:34,代码来源:socket.c

示例11: socket_recv

/**
	socket_recv : 'socket -> buf:string -> pos:int -> len:int -> int
	<doc>Read up to [len] bytes from [buf] starting at [pos] from a connected socket.
	Return the number of bytes readed.</doc>
**/
static value socket_recv( value o, value data, value pos, value len ) {
	int p,l,dlen,ret;
	int retry = 0;
	val_check_kind(o,k_socket);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	p = val_int(pos);
	l = val_int(len);
	dlen = val_strlen(data);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
	POSIX_LABEL(recv_again);
	if( retry++ > NRETRYS ) {
		sock_tmp t;
		t.sock = val_sock(o);
		t.buf = val_string(data) + p;
		t.size = l;
		neko_thread_blocking(tmp_recv,&t);
		ret = t.ret;
	} else
		ret = recv(val_sock(o), val_string(data) + p , l, MSG_NOSIGNAL);
	if( ret == SOCKET_ERROR ) {
		HANDLE_EINTR(recv_again);
		return block_error();
	}
	return alloc_int(ret);
}
开发者ID:motion-twin,项目名称:neko,代码行数:33,代码来源:socket.c

示例12: file_read

/**
	file_read : 'file -> s:string -> p:int -> l:int -> int
	<doc>
	Read up to [l] chars into the string [s] starting at position [p].
	Returns the number of chars readed which is > 0 (or 0 if l == 0).
	</doc>
**/
static value file_read( value o, value s, value pp, value n ) {
	fio *f;
	int p;
	int len;
	int buf_len;
	val_check_kind(o,k_file);
	val_check(s,buffer);
	buffer buf = val_to_buffer(s);
	buf_len = buffer_size(buf);
	val_check(pp,int);
	val_check(n,int);
	f = val_file(o);
	p = val_int(pp);
	len = val_int(n);
	if( p < 0 || len < 0 || p > buf_len || p + len > buf_len )
		return alloc_null();
	gc_enter_blocking();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_read_again);
		d = (int)fread(buffer_data(buf)+p,1,len,f->io);
		if( d <= 0 ) {
			int size = val_int(n) - len;
			HANDLE_FINTR(f->io,file_read_again);
			if( size == 0 )
				file_error("file_read",f);
			return alloc_int(size);
		}
		p += d;
		len -= d;
	}
	gc_exit_blocking();
	return n;
}
开发者ID:bjitivo,项目名称:hxcpp,代码行数:41,代码来源:File.cpp

示例13: file_write

/**
	file_write : 'file -> s:string -> p:int -> l:int -> int
	<doc>
	Write up to [l] chars of string [s] starting at position [p]. 
	Returns the number of chars written which is >= 0.
	</doc>
**/
static value file_write( value o, value s, value pp, value n ) {
	int p, len;
	fio *f;
	val_check_kind(o,k_file);
	val_check(s,string);
	val_check(pp,int);
	val_check(n,int);
	f = val_file(o);
	p = val_int(pp);
	len = val_int(n);
	if( p < 0 || len < 0 || p > val_strlen(s) || p + len > val_strlen(s) )
		neko_error();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_write_again);
		d = (int)fwrite(val_string(s)+p,1,len,f->io);
		if( d <= 0 ) {
			HANDLE_FINTR(f->io,file_write_again);
			file_error("file_write",f);
		}
		p += d;
		len -= d;
	}
	return n;
}
开发者ID:fantoine,项目名称:haxe-templo2,代码行数:32,代码来源:file.c

示例14: file_read

/**
	file_read : 'file -> s:string -> p:int -> l:int -> int
	<doc>
	Read up to [l] chars into the string [s] starting at position [p].
	Returns the number of chars readed which is > 0 (or 0 if l == 0).
	</doc>
**/
static value file_read( value o, value s, value pp, value n ) {
	fio *f;
	int p;
	int len;
	val_check_kind(o,k_file);
	val_check(s,string);
	val_check(pp,int);
	val_check(n,int);
	f = val_file(o);
	p = val_int(pp);
	len = val_int(n);
	if( p < 0 || len < 0 || p > val_strlen(s) || p + len > val_strlen(s) )
		neko_error();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_read_again);
		d = (int)fread((char*)val_string(s)+p,1,len,f->io);
		if( d <= 0 ) {
			int size = val_int(n) - len;
			HANDLE_FINTR(f->io,file_read_again);
			if( size == 0 )
				file_error("file_read",f);
			return alloc_int(size);
		}
		p += d;
		len -= d;
	}
	return n;
}
开发者ID:fantoine,项目名称:haxe-templo2,代码行数:36,代码来源:file.c

示例15: do_close

static int do_close( int fd ) {
	POSIX_LABEL(close_again);
	if( close(fd) != 0 ) {
		HANDLE_EINTR(close_again);
		return 1;
	}
	return 0;
}
开发者ID:bsmr-haxe,项目名称:neko,代码行数:8,代码来源:process.c


注:本文中的POSIX_LABEL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。