File Interface
Under Unix, the "everything is a file" paradigm naturally leads to a file-based event loop. Reading from and writing to files, inter-process communication, network communication and device control are all achieved using file I/O, with the target identified by a file descriptor. The select and poll system calls allow a set of file descriptors to be monitored for a change of state, e.g. when data becomes available to be read.
For example, consider a program that reads from a continuously updated file and displays its contents in the X Window System, which communicates with clients over a socket (either Unix domain or Berkeley):
main: file_fd = open ("logfile") x_fd = open_display construct_interface while changed_fds = select ({file_fd, x_fd}): if file_fd in changed_fds: data = read_from (file_fd) append_to_display (data) send_repaint_message if x_fd in changed_fds: process_x_messagesRead more about this topic: Event Loop
Famous quotes containing the word file:
“While waiting to get married, several forms of employment were acceptable. Teaching kindergarten was for those girls who stayed in school four years. The rest were secretaries, typists, file clerks, or receptionists in insurance firms or banks, preferably those owned or run by the family, but respectable enough if the boss was an upstanding Christian member of the community.”
—Barbara Howar (b. 1934)