本文整理汇总了C++中set_blocking函数的典型用法代码示例。如果您正苦于以下问题:C++ set_blocking函数的具体用法?C++ set_blocking怎么用?C++ set_blocking使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_blocking函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: set_blocking
ssize_t
NetStream::write_to_net(
const void *buf,
size_t nbytes
) const
{
set_blocking(true);
#ifdef WIN32
ssize_t bytes_written = write_win32(_fd, buf, nbytes);
#else
ssize_t bytes_written = ::write(_fd, buf, nbytes);
#endif
set_blocking(false);
if (bytes_written < 0 || NET_exception) {
perror("NetStream::write_to_net: Warning: ");
NET_exception = 0;
} else if (bytes_written < (ssize_t)nbytes)
cerr << "Couldn't flush the buffer. Some data wasn't written. (nbytes="
<< nbytes << " written=" << bytes_written << ")\n";
return bytes_written;
}
开发者ID:ArnaudGastinel,项目名称:jot-lib,代码行数:22,代码来源:net.C
示例2: timed_read
ssize_t timed_read(int sockfd, void* buf, size_t count, int timeout_ms)
{
ssize_t rv;
set_non_blocking(sockfd);
do {
if (0 <= (rv = wait_fd(sockfd, timeout_ms)))
rv = read(sockfd, buf, count);
} while (errno == EINTR);
set_blocking(sockfd);
return rv;
}
开发者ID:Audur,项目名称:libpagekite,代码行数:13,代码来源:utils.c
示例3: open_sockets
static BOOL open_sockets(BOOL isdaemon, int port)
{
/*
* The sockets opened here will be used to receive broadcast
* packets *only*. Interface specific sockets are opened in
* make_subnet() in namedbsubnet.c. Thus we bind to the
* address "0.0.0.0". The parameter 'socket address' is
* now deprecated.
*/
if ( isdaemon )
ClientNMB = open_socket_in(SOCK_DGRAM, port,
0, interpret_addr(lp_socket_address()),
True);
else
ClientNMB = 0;
ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT,
3, interpret_addr(lp_socket_address()),
True);
if ( ClientNMB == -1 )
return( False );
#ifndef _XBOX
/* we are never interested in SIGPIPE */
BlockSignals(True,SIGPIPE);
#endif
set_socket_options( ClientNMB, "SO_BROADCAST" );
set_socket_options( ClientDGRAM, "SO_BROADCAST" );
/* Ensure we're non-blocking. */
set_blocking( ClientNMB, False);
set_blocking( ClientDGRAM, False);
DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) );
return( True );
}
开发者ID:DeezNuts12,项目名称:freestyledash,代码行数:39,代码来源:nmbd.c
示例4: serial_create
/**
* Opens and initializes a serial port.
*/
int serial_create (char *device)
{
int fd = open(device, O_RDWR | O_NOCTTY | O_SYNC | O_NDELAY);
if (fd < 0) {
printf("error %d opening '%s', %s\n", errno, device, strerror(errno));
goto exit;
}
set_interface_attribs(fd, B19200, 0);
set_blocking(fd, 0);
exit:
return fd;
}
开发者ID:PontusO,项目名称:lc1,代码行数:16,代码来源:serial.c
示例5: unixdom_listen
static NTSTATUS unixdom_listen(struct socket_context *sock,
const struct socket_address *my_address,
int queue_size, uint32_t flags)
{
struct sockaddr_un my_addr;
int ret;
/* delete if it already exists */
if (my_address->addr) {
unlink(my_address->addr);
}
if (my_address->sockaddr) {
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
} else if (my_address->addr == NULL) {
return NT_STATUS_INVALID_PARAMETER;
} else {
if (strlen(my_address->addr)+1 > sizeof(my_addr.sun_path)) {
return NT_STATUS_OBJECT_PATH_INVALID;
}
ZERO_STRUCT(my_addr);
my_addr.sun_family = AF_UNIX;
snprintf(my_addr.sun_path, sizeof(my_addr.sun_path), "%s", my_address->addr);
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
}
if (ret == -1) {
return unixdom_error(errno);
}
if (sock->type == SOCKET_TYPE_STREAM) {
ret = listen(sock->fd, queue_size);
if (ret == -1) {
return unixdom_error(errno);
}
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
ret = set_blocking(sock->fd, false);
if (ret == -1) {
return unixdom_error(errno);
}
}
sock->state = SOCKET_STATE_SERVER_LISTEN;
sock->private_data = (void *)talloc_strdup(sock, my_address->addr);
return NT_STATUS_OK;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:51,代码来源:socket_unix.c
示例6: main
int main(int argc, char **argv){
char *portname0 = "/dev/ttyUSB1";
char *portname1 = "/dev/ttyUSB0";
int fd0 = open(portname0, O_RDWR | O_NOCTTY | O_SYNC);
if (fd0 < 0) {
fprintf(stderr, "error %d opening %s: %s", errno, portname0, strerror(errno));
return;
}
set_interface_attribs(fd0, B9600, 0); //B115200
set_blocking(fd0, 0);
write(fd0, "hello!\n", 7);
printf("hello!\n");
usleep((7+25)*1000);
close(fd0);
char buf[100];
int fd1 = open(portname1, O_RDWR | O_NOCTTY | O_SYNC);
if (fd1 < 0) {
fprintf(stderr, "error %d opening %s: %s", errno, portname1, strerror(errno));
return;
}
set_interface_attribs(fd1, B9600, 0);
set_blocking(fd1, 0);
int n = read(fd1, buf, sizeof buf);
printf("%s",buf);
close(fd1);
return 0;
}
开发者ID:juhnowski,项目名称:c_com,代码行数:38,代码来源:c_out_1.c
示例7: set_blocking
void Socket::create(Socket::Handle handle) {
if (handle_ == priv::SocketImpl::invalid()) {
int op_value = 1;
handle_ = handle;
set_blocking(blocking_);
if (setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&op_value), sizeof(op_value)) == -1) {
// throw Exception("Failed to set socket option TCP_NODELAY");
return;
}
}
}
开发者ID:GreyDireWolf,项目名称:libMathDN,代码行数:14,代码来源:Socket.cpp
示例8: initializeSerialPort
int initializeSerialPort(char *portname) {
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
printf("FD OPEN, fd = %d", fd);
if (fd < 0)
{
printf("error %d opening %s: %s", errno, portname, strerror (errno));
return -1;
}
set_interface_attribs (fd, B9600, 0); // set speed to 115,200 bps, 8n1 (no parity)
set_blocking (fd, 0); // set no blocking
return fd;
}
开发者ID:bschreck,项目名称:gesture-drone,代码行数:14,代码来源:SerialWrite.cpp
示例9: initMW
int initMW(void)
{
int fd = open (MINDWAVEPORT, O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0) {
fprintf (stderr, "error %d opening %s: %s\n", errno, MINDWAVEPORT,
strerror (errno));
exit (1);
}
set_interface_attribs (fd, B57600, 0); // 57,600 bps, 8n1 (no parity)
set_blocking (fd, 0); // set non blocking
return (fd);
}
开发者ID:muehlber,项目名称:mindrace,代码行数:14,代码来源:mindrace.c
示例10: Connect
static int Connect (int fd, SA *addr)
{
int retval;
set_non_blocking(fd);
if ((retval = connect(fd, addr, socklen(addr))))
{
if (errno != EINPROGRESS)
syserr(-1, "Connect: connect(%d) failed: %s", fd, strerror(errno));
else
retval = 0;
}
set_blocking(fd);
return retval;
}
开发者ID:ailin-nemui,项目名称:epic5,代码行数:15,代码来源:network.c
示例11: initSerial
int initSerial( int *fd, int baudrate, char *devname )
{
*fd = open( devname, O_RDWR | O_NOCTTY | O_SYNC );
if (*fd < 0)
{
fprintf(stderr, "! ERROR: Could not open serial port!\n");
perror("! ERROR Message from system");
return EXIT_FAILURE;
}
set_interface_attribs (*fd, baudrate, 0); // set speed to 115,200 bps, 8n1 (no parity)
set_blocking (*fd, 0); // set no blockin
return EXIT_SUCCESS;
}
开发者ID:mathiashelsen,项目名称:stm32-playground,代码行数:15,代码来源:io.c
示例12: socket_listen
/*
note that for simplicity of the API, socket_listen() is also
use for DGRAM sockets, but in reality only a bind() is done
*/
static NTSTATUS ipv4_listen(struct socket_context *sock,
const struct socket_address *my_address,
int queue_size, uint32_t flags)
{
struct sockaddr_in my_addr;
struct in_addr ip_addr;
int ret;
socket_set_option(sock, "SO_REUSEADDR=1", NULL);
if (my_address->sockaddr) {
ret = bind(sock->fd, my_address->sockaddr, my_address->sockaddrlen);
} else {
ip_addr = interpret_addr2(my_address->addr);
ZERO_STRUCT(my_addr);
#ifdef HAVE_SOCK_SIN_LEN
my_addr.sin_len = sizeof(my_addr);
#endif
my_addr.sin_addr.s_addr = ip_addr.s_addr;
my_addr.sin_port = htons(my_address->port);
my_addr.sin_family = PF_INET;
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
}
if (ret == -1) {
return map_nt_error_from_unix_common(errno);
}
if (sock->type == SOCKET_TYPE_STREAM) {
ret = listen(sock->fd, queue_size);
if (ret == -1) {
return map_nt_error_from_unix_common(errno);
}
}
if (!(flags & SOCKET_FLAG_BLOCK)) {
ret = set_blocking(sock->fd, false);
if (ret == -1) {
return map_nt_error_from_unix_common(errno);
}
}
sock->state= SOCKET_STATE_SERVER_LISTEN;
return NT_STATUS_OK;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:52,代码来源:socket_ip.c
示例13: ipv6_tcp_accept
static NTSTATUS ipv6_tcp_accept(struct socket_context *sock, struct socket_context **new_sock)
{
struct sockaddr_in6 cli_addr;
socklen_t cli_addr_len = sizeof(cli_addr);
int new_fd;
if (sock->type != SOCKET_TYPE_STREAM) {
return NT_STATUS_INVALID_PARAMETER;
}
new_fd = accept(sock->fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
if (new_fd == -1) {
return map_nt_error_from_unix_common(errno);
}
if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
int ret = set_blocking(new_fd, false);
if (ret == -1) {
close(new_fd);
return map_nt_error_from_unix_common(errno);
}
}
/* TODO: we could add a 'accept_check' hook here
* which get the black/white lists via socket_set_accept_filter()
* or something like that
* --metze
*/
(*new_sock) = talloc(NULL, struct socket_context);
if (!(*new_sock)) {
close(new_fd);
return NT_STATUS_NO_MEMORY;
}
/* copy the socket_context */
(*new_sock)->type = sock->type;
(*new_sock)->state = SOCKET_STATE_SERVER_CONNECTED;
(*new_sock)->flags = sock->flags;
(*new_sock)->fd = new_fd;
(*new_sock)->private_data = NULL;
(*new_sock)->ops = sock->ops;
(*new_sock)->backend_name = sock->backend_name;
return NT_STATUS_OK;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:48,代码来源:socket_ip.c
示例14: openSerial
//Open the serial port file descriptor
int openSerial(){
char *portname = "/dev/ttyMCC";
// Open serial port (file descriptor)
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0)
{
printf("error %d opening %s: %s", errno, portname, strerror (errno));
return 0;
}
// Configure the serial communication interface before use
set_interface_attribs (fd, B115200, 0); // set speed to 115,200 bps, 8n1 (no parity)
set_blocking (fd, 0); // set no blocking
return fd;
}
开发者ID:jrullan,项目名称:udoo-neo-c-host,代码行数:17,代码来源:udoo_neo_serial.c
示例15: sms_thread
/** sms **/
static void * sms_thread (void * arg) {
struct smsnode * tmp, * sq = ((struct thrdarg *) arg)->sq;
char ttyb[64];
int tty, ttyr, ttyw;
while (1) {
sq = sq->next;
if (sq->status == CRYPTO_SMS_STATUS_HOME) continue;
if (sq->status == CRYPTO_SMS_STATUS_SENT) {
printf ("sms sent. leaving queue %s\n", sq->number);
tmp = sq;
sq->prev->next = sq->next;
sq->next->prev = sq->prev;
sq = sq->prev;
free (tmp->key);
free (tmp->number);
free (tmp);
}
if (sq->status == CRYPTO_SMS_STATUS_PENDING) {
printf ("sending sms key %s\nto number %s\n", sq->key, sq->number);
tty = open ("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (tty < 0) continue;
set_serial (tty, B2400, 0);
set_blocking (tty, B9600, 0);
ttyw = write (tty, "AT+CMGF=1\r\n", 11);
printf ("ttyw=%d\n", ttyw);
sleep (1);
sprintf (ttyb, "AT+CMGS=\"%s\"\r%s%c", sq->number, sq->key, (char) 26);
ttyw = write (tty, ttyb, strlen(ttyb));
printf ("ttyb=%s,\n", ttyb);
printf ("ttyw=%d\n", ttyw);
sleep (1);
close (tty);
sq->status = CRYPTO_SMS_STATUS_SENT;
}
if (sq->status == CRYPTO_SMS_STATUS_ERROR) {
tmp = sq;
sq->prev->next = sq->next;
sq->next->prev = sq->prev;
sq = sq->prev;
free (tmp);
}
}
}
开发者ID:bdobrica,项目名称:Crypto,代码行数:48,代码来源:cryptoid.c
示例16: socket_create_with_ops
_PUBLIC_ NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops,
struct socket_context **new_sock,
enum socket_type type, uint32_t flags)
{
NTSTATUS status;
(*new_sock) = talloc(mem_ctx, struct socket_context);
if (!(*new_sock)) {
return NT_STATUS_NO_MEMORY;
}
(*new_sock)->type = type;
(*new_sock)->state = SOCKET_STATE_UNDEFINED;
(*new_sock)->flags = flags;
(*new_sock)->fd = -1;
(*new_sock)->private_data = NULL;
(*new_sock)->ops = ops;
(*new_sock)->backend_name = NULL;
status = (*new_sock)->ops->fn_init((*new_sock));
if (!NT_STATUS_IS_OK(status)) {
talloc_free(*new_sock);
return status;
}
/* by enabling "testnonblock" mode, all socket receive and
send calls on non-blocking sockets will randomly recv/send
less data than requested */
if (!(flags & SOCKET_FLAG_BLOCK) &&
type == SOCKET_TYPE_STREAM &&
getenv("SOCKET_TESTNONBLOCK") != NULL) {
(*new_sock)->flags |= SOCKET_FLAG_TESTNONBLOCK;
}
/* we don't do a connect() on dgram sockets, so need to set
non-blocking at socket create time */
if (!(flags & SOCKET_FLAG_BLOCK) && type == SOCKET_TYPE_DGRAM) {
set_blocking(socket_get_fd(*new_sock), false);
}
talloc_set_destructor(*new_sock, socket_destructor);
return NT_STATUS_OK;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:47,代码来源:socket.c
示例17: openPort
int openPort(char* portname, int speed, int vmin, int vtime)
{
printf("trying to open port %s\n", portname);
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0)
{
printf("error %d opening %s: %s\n", errno, portname, strerror (errno));
return;
}
set_interface_attribs (fd, speed, 0);
set_blocking (fd, vmin, vtime);
return fd;
}
开发者ID:christofferholmstedt,项目名称:naiad-auv-software,代码行数:17,代码来源:uartlib.c
示例18: read_from_sd
static int read_from_sd ( int sd )
{
char buf[100];
int n;
set_blocking(sd);
n = read(sd, buf, 99);
if (n <= 0) return 0; /* closed */
copyout(buf, n);
set_nonblocking(sd);
while (1) {
n = read(sd, buf, 100);
if (n <= 0) return 1; /* not closed */
copyout(buf, n);
}
}
开发者ID:MShudrak,项目名称:flayer,代码行数:17,代码来源:valgrind-listener.c
示例19: main
int main(void) {
char *portname = "/dev/ttymxc3";
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0)
{
printf("error %d opening %s: %s", errno, portname, strerror (errno));
return;
}
set_interface_attribs (fd, B115200, 0); // set speed to 115,200 bps, 8n1 (no parity)
set_blocking (fd, 0); // set no blocking
char buf [7];
int n;
char buffON[2] = {13,1};
write(fd, buffON, 2); // send 2 character greeting
sleep(1); // delay 1 second
n = read (fd, buf, sizeof buf); // read up to 7 characters if ready to read
if (n > 0) {
//printf("quanti: %d\n", n);
int i;
for (i = 0; i < n; i++) {
printf("%c",buf[i]);
}
}
char buffOFF[2] = {13,0};
write(fd, buffOFF, 2);
sleep(1); // delay 1 second
n = read (fd, buf, sizeof buf); // read up to 7 characters if ready to read
if (n > 0) {
//printf("quanti: %d\n", n);
int i;
for (i = 0; i < n; i++) {
printf("%c",buf[i]);
}
}
}
开发者ID:davidbradway,项目名称:serial_libraries_examples,代码行数:45,代码来源:c_serial_example_bidirectional.c
示例20: unixdom_accept
static NTSTATUS unixdom_accept(struct socket_context *sock,
struct socket_context **new_sock)
{
struct sockaddr_un cli_addr;
socklen_t cli_addr_len = sizeof(cli_addr);
int new_fd;
if (sock->type != SOCKET_TYPE_STREAM) {
return NT_STATUS_INVALID_PARAMETER;
}
new_fd = accept(sock->fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
if (new_fd == -1) {
return unixdom_error(errno);
}
if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
int ret = set_blocking(new_fd, false);
if (ret == -1) {
close(new_fd);
return map_nt_error_from_unix_common(errno);
}
}
smb_set_close_on_exec(new_fd);
(*new_sock) = talloc(NULL, struct socket_context);
if (!(*new_sock)) {
close(new_fd);
return NT_STATUS_NO_MEMORY;
}
/* copy the socket_context */
(*new_sock)->type = sock->type;
(*new_sock)->state = SOCKET_STATE_SERVER_CONNECTED;
(*new_sock)->flags = sock->flags;
(*new_sock)->fd = new_fd;
(*new_sock)->private_data = NULL;
(*new_sock)->ops = sock->ops;
(*new_sock)->backend_name = sock->backend_name;
return NT_STATUS_OK;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:45,代码来源:socket_unix.c
注:本文中的set_blocking函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论