1 / 9

Network Programming CSC- 341

Network Programming CSC- 341. Instructor: Junaid Tariq, Lecturer, Department of Computer Science. 13. Lecture. Network Programming. 3.9 readn , writen , and realine Functions. #include “unp.h” ssize_t readn (int filedes , void * buff , size_t nbytes );

mio
Download Presentation

Network Programming CSC- 341

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Network ProgrammingCSC- 341 Instructor: Junaid Tariq, Lecturer, Department of Computer Science

  2. 13 Lecture Network Programming

  3. 3.9 readn, writen, and realine Functions #include “unp.h” ssize_t readn(int filedes, void *buff, size_t nbytes); ssize_t writen(int filedes, const void *buff, size_t nbytes); ssize_t readline(int filedes, void *buff, size_t maxline); All return: number of bytes read or written, -1 on error

  4. Readn()

  5. writen

  6. readline

  7. 3.10 Isfdtypefunction • Test a Descriptor to see if it is of a specified type • historically : fstat function used ==> testing the returned value st_mode value using one of the S_IFxxx macro. #include <sys/stat.h> int isfdtype(int fd, int fdtype); /* return:1 if descriptor of specified type, 0 if not, -1 on error */ /* To test for a socket, fdtype is S_IFSOCK.*/

  8. #ifndef S_IFSOCK #error S_IFSOCK not defined #endif int isfdtype(int fd, int fdtype) { struct stat buf; if(fstat (fd, &buf) < 0) return (-1); if((buf.st_mode & S_IFMT) == fdtype) return (1); else return (0); }

  9. st_mode field • The following flags are defined for the st_mode field: • S_IFMT bit mask for the file type bit fields • S_IFSOCK socket • S_IFLNK symbolic link • S_IFREG regular file • S_IFBLK block device • S_IFDIR directory • S_IFCHR character device • S_IFIFO FIFO

More Related