UNIX System Management: system call-stream mechanism

Source: Internet
Author: User
Keywords UNIX System Management
Tags advanced calls data error group operation return returned

Basically all system calls return 0 or positive numbers when they succeed, and negative values are returned when they fail.

Advanced Operations for Streams

Poll system call format

#include <stropts.h>

#include <poll>

Int poll (fds,nfds,timeout)

struct POLLFD fds[]; /* Flow Group Description Structure * *

unsigned long Nfds; /* Flow Number * *

int timeout; /* Query Timeout/*

Parameter and Function Description:

The parameter Nfds indicates the number of streams in the stream group, while the FDS is a flow group description structure, and his format is as follows:

struct POLLFD

{

int FD; /* Flow Descriptor/*

Short http://www.aliyun.com/zixun/aggregation/38907.html ">events; * * User Expected Event/

Short revents; /* Events occurring on the stream/*

}FDS[NFDS];

The function is to query whether a user expects events occur on each stream in the flow group. If an event occurs, the event that occurs is registered in the revents domain of the flow group description structure and returned to the user. If no event occurs, sleep waits until an event occurs or waits for a timeout. The timeout period has a parameter timeout given, in milliseconds. When timeout is-1, the timeout value is infinite and can wait indefinitely.

There are three types of events that users expect, and their values and meanings are as follows:

POLLIN: Expect a data message to be reached on the corresponding stream.

Pollout: Expect to be able to send a data message to the corresponding stream.

POLLPRI: Expect a high priority data message to be reached on the corresponding stream (high priority is a control message)

There are three kinds of revents values: 0, events that have occurred, error events.

0 indicates that no expected event occurred on the corresponding stream. An event that has occurred is the event expected by the stream, and an error event is the value set when the poll call fails, and he can have three values, which may be "or" for the three values in the revents. The value of the error event and its meaning are as follows:

Pollerr: An error message is reached on the stream, and the operation of the convection cannot continue.

Pollhup: A suspend condition appears on the stream, and then the message cannot be sent convection.

Pollnval: illegal flow descriptor.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.