日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

2018-2019-1 20165226 《信息安全系统设计基础》第6周学习总结

發布時間:2025/3/18 windows 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2018-2019-1 20165226 《信息安全系统设计基础》第6周学习总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2018-2019-1 20165226 《信息安全系統設計基礎》第6周學習總結

目錄


  • 一、教材學習內容總結
  • 二、練習
  • 三、代碼托管與統計
  • 四、學習進度條
  • 五、參考資料

一、教材學習內容總結


1、 Unix I/O

這一節涉及到操作系統的基本抽象之一——文件。也就是說,所有的I/O設備都被模型化為文件,而所有的輸入輸出都被當做對相應文件的讀/寫。

  • I/O設備:網絡、磁盤和終端
    • 描述符:打開文件時,內核返回一個小的非負整數。
    • Unix外殼創建的每個進程開始時都有三個打開的文件:標準輸入(描述符為0)、標準輸出(描述符為1)、標準錯誤(描述符為2)。
    • 改變當前的文件位置:文件位置為k,初始為0。
    • seek操作:顯式地設置文件的當前位置為k。
    • 關閉文件:內核釋放文件打開時創建的數據結構,并將這個描述符恢復到可用的描述符池中。無論一個進程因為何種原因終止時,內核都會關閉所有打開的文件并釋放它們的存儲器資源。

2、打開和關閉文件

(1)open函數:打開一個已存在的文件或者創建一個新文件

  • 定義:
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>int open(char *filename,int flags,mode_t mode);
  • 參數解析:
    • 返回值:類型為int型,返回的是描述符數字,總是在進程中當前沒有打開的最小描述符。如果出錯,返回值為-1.
    • filename:文件名
    • flags:指明進程打算如何訪問這個文件,可以取的值見下:
O_RDONLY:只讀O_WRONLY:只寫O_RDWR:可讀可寫O_CREAT:文件不存在,就創建新文件O_TRUNC:如果文件存在,就截斷它O_APPEND:寫操作前設置文件位置到結尾處

這些值可以用或連接起來。
- mode:指定了新文件的訪問權限位,符號名稱如下:

(2)close函數

  • 函數定義
#include <unistd.h> int close(int fd);
  • 參數解析
    • 返回值:成功返回0,出錯返回-1

      關閉一個已經關閉的描述符會出錯

    • fd:即文件的描述符。

3、讀和寫文件

  • 應用程序是通過分別調用read和write函數來執行輸入和輸出的。
#include <unistd.h> ssize_t read(int fd,void *buf,size_t n); ssize_t write(int fd,const void *buf,size_t n);

read函數:從描述符為fd的當前文件位置拷貝最多n個字節到存儲器位置buf。返回值:-1表示一個錯誤;0表示EOF;否則,返回值表示的是實際傳送的字節數量。
從存儲器位置buf拷貝至多n個字節到描述符fd的當前文件位置。返回值:若成功則為寫的字節數,若出錯則為-1。

  • lseek函數:應用程序能夠顯式地修改當前文件的位置。
  • 不足值:read和write傳送的字節比應用程序要求的少。
    • 讀時遇到EOF
    • 從終端讀文本行
    • 讀和寫網絡套接字

4、用RIO包健壯的讀寫

RIO包的實質:I/O包
RIO包提供的兩種函數:

  • 無緩沖的輸入輸出函數
  • 帶緩沖的輸入函數(線程安全)

RIO的無緩沖的輸入輸出函數

  • 應用程序通過調用rioreadn和riowritten函數可以在存儲器和文件之間直接傳送數據。
#include "csapp.h" ssize_t rio_readn(int fd,void *usrbuf,size_t n); ssize_t rio_writen(int fd,void *usrbuf,size_t n);
  • rio_ readn函數在遇到EOF時,只能返回一個不足值;
  • rio_ writen函數絕不會返回不足值。

RIO的帶緩沖的輸入函數

  • 一個文本行就是一個由換行符結尾的ASCII碼字符序列。在Unix系統中,換行符(‘\n')與ASCII碼換行符(LF)相同,數字值為0x0a。
  • 計算文本文件中文本行的數量,更好地方法是:
    • 調用一個包裝函數(rio、readlineb),它從一個內部讀緩沖區拷貝一個文本行,當緩沖區變空時,會自動地調用read重新填滿緩沖區。
#include "csapp.h" //每打開一個描述符都會調用一次該函數,它將描述符fd和地址rp處的類型為rio_t的緩沖區聯系起來。 void rio_readinitb(rio_t *rp,int fd); //從文件rp中讀取一個文本行(包括結尾的換行符),將它拷貝到存儲器位置usrbuf,并用空字符來結束這個文本行。 ssize_t rio_readlineb(rio_t *rp,void *usrbuf,size_t maxlen); //從文件rp中最多讀n個字節到存儲器位置usrbuf。對同一描述符,rioreadnb和rioreadlineb的調用可以交叉進行。 ssize_t rio_readnb(rio_t *rp,void *usrbuf,size_t n);

讀取文件元數據

  • 檢索文件信息(元數據):應用程序能夠通過調用stat和fstat函數
#include <unistd.h> #include <sys/stat.h> int stat(const char *filename,struct stat *buf); //stat函數以一個文件名作為輸入,填寫一個stat數據結構中的各個成員。 int fstat(int fd,struct stat *buf); //fstat函數以文件描述符而不是文件名作為輸入。
  • st_size成員包含了文件的字節數大小
  • st_mode成員編碼了文件訪問許可位和文件類型
  • Unix提供的宏指令根據st_mode成員來確定文件的類型
宏指令描述
S_ISREG()這是一個普通文件嗎?
S_ISDIR()這是一個目錄文件嗎?
S_ISSOCK()這是一個網絡套接字嗎?

返回目錄

二、練習


練習題10.1

#include "csapp.h" int main(){int fd1,fd2;fd1=Open("foo.txt",O_RDONLY,0);Close(fd1);fd2=Open("baz.txt",O_RDONLY,0);print("fd2=%d\n",fd2);exit(0);}
  • 編譯時發生錯誤:

  • 說明是Linux系統沒有自帶csapp/h頭文件,需要自己編寫。所以,只要把這個頭文件加入到系統的include目錄中就好了。
    • csapp.h
/* $begin csapp.h */ #ifndef __CSAPP_H__ #define __CSAPP_H__ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <ctype.h> #include <setjmp.h> #include <signal.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> #include <errno.h> #include <math.h> #include <pthread.h> #include <semaphore.h> #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> /* Default file permissions are DEF_MODE & ~DEF_UMASK */ /* $begin createmasks */ #define DEF_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH #define DEF_UMASK S_IWGRP|S_IWOTH /* $end createmasks */ /* Simplifies calls to bind(), connect(), and accept() */ /* $begin sockaddrdef */ typedef struct sockaddr SA; /* $end sockaddrdef */ /* Persistent state for the robust I/O (Rio) package */ /* $begin rio_t */ #define RIO_BUFSIZE 8192 typedef struct {int rio_fd; /* descriptor for this internal buf */int rio_cnt; /* unread bytes in internal buf */char *rio_bufptr; /* next unread byte in internal buf */char rio_buf[RIO_BUFSIZE]; /* internal buffer */ } rio_t; /* $end rio_t */ /* External variables */ extern int h_errno; /* defined by BIND for DNS errors */ extern char **environ; /* defined by libc */ /* Misc constants */ #define MAXLINE 8192 /* max text line length */ #define MAXBUF 8192 /* max I/O buffer size */ #define LISTENQ 1024 /* second argument to listen() */ /* Our own error-handling functions */ void unix_error(char *msg); void posix_error(int code, char *msg); void dns_error(char *msg); void app_error(char *msg); /* Process control wrappers */ pid_t Fork(void); void Execve(const char *filename, char *const argv[], char *const envp[]); pid_t Wait(int *status); pid_t Waitpid(pid_t pid, int *iptr, int options); void Kill(pid_t pid, int signum); unsigned int Sleep(unsigned int secs); void Pause(void); unsigned int Alarm(unsigned int seconds); void Setpgid(pid_t pid, pid_t pgid); pid_t Getpgrp();/* Signal wrappers */ typedef void handler_t(int); handler_t *Signal(int signum, handler_t *handler); void Sigprocmask(int how, const sigset_t *set, sigset_t *oldset); void Sigemptyset(sigset_t *set); void Sigfillset(sigset_t *set); void Sigaddset(sigset_t *set, int signum); void Sigdelset(sigset_t *set, int signum); int Sigismember(const sigset_t *set, int signum); /* Unix I/O wrappers */ int Open(const char *pathname, int flags, mode_t mode); ssize_t Read(int fd, void *buf, size_t count); ssize_t Write(int fd, const void *buf, size_t count); off_t Lseek(int fildes, off_t offset, int whence); void Close(int fd); int Select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); int Dup2(int fd1, int fd2); void Stat(const char *filename, struct stat *buf); void Fstat(int fd, struct stat *buf) ; /* Memory mapping wrappers */ void *Mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); void Munmap(void *start, size_t length); /* Standard I/O wrappers */ void Fclose(FILE *fp); FILE *Fdopen(int fd, const char *type); char *Fgets(char *ptr, int n, FILE *stream); FILE *Fopen(const char *filename, const char *mode); void Fputs(const char *ptr, FILE *stream); size_t Fread(void *ptr, size_t size, size_t nmemb, FILE *stream); void Fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); /* Dynamic storage allocation wrappers */ void *Malloc(size_t size); void *Realloc(void *ptr, size_t size); void *Calloc(size_t nmemb, size_t size); void Free(void *ptr); /* Sockets interface wrappers */ int Socket(int domain, int type, int protocol); void Setsockopt(int s, int level, int optname, const void *optval, int optlen); void Bind(int sockfd, struct sockaddr *my_addr, int addrlen); void Listen(int s, int backlog); int Accept(int s, struct sockaddr *addr, socklen_t *addrlen); void Connect(int sockfd, struct sockaddr *serv_addr, int addrlen); /* DNS wrappers */ struct hostent *Gethostbyname(const char *name); struct hostent *Gethostbyaddr(const char *addr, int len, int type); /* Pthreads thread control wrappers */ void Pthread_create(pthread_t *tidp, pthread_attr_t *attrp, void * (*routine)(void *), void *argp); void Pthread_join(pthread_t tid, void **thread_return); void Pthread_cancel(pthread_t tid); void Pthread_detach(pthread_t tid); void Pthread_exit(void *retval); pthread_t Pthread_self(void); void Pthread_once(pthread_once_t *once_control, void (*init_function)()); /* POSIX semaphore wrappers */ void Sem_init(sem_t *sem, int pshared, unsigned int value); void P(sem_t *sem); void V(sem_t *sem);/* Rio (Robust I/O) package */ ssize_t rio_readn(int fd, void *usrbuf, size_t n); ssize_t rio_writen(int fd, void *usrbuf, size_t n); void rio_readinitb(rio_t *rp, int fd); ssize_t rio_readnb(rio_t *rp, void *usrbuf, size_t n); ssize_t rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen); /* Wrappers for Rio package */ ssize_t Rio_readn(int fd, void *usrbuf, size_t n); void Rio_writen(int fd, void *usrbuf, size_t n); void Rio_readinitb(rio_t *rp, int fd); ssize_t Rio_readnb(rio_t *rp, void *usrbuf, size_t n); ssize_t Rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen); /* Client/server helper functions */ int open_clientfd(char *hostname, int portno); int open_listenfd(int portno); /* Wrappers for client/server helper functions */ int Open_clientfd(char *hostname, int port); int Open_listenfd(int port); #include <csapp.c> #endif /* __CSAPP_H__ */ /* $end csapp.h */
  • csappp.c
/* $begin csapp.c */ #include "csapp.h" /************************** * Error-handling functions**************************/ /* $begin errorfuns */ /* $begin unixerror */ void unix_error(char *msg) /* unix-style error */ {fprintf(stderr, "%s: %s\n", msg, strerror(errno));exit(0); } /* $end unixerror */ void posix_error(int code, char *msg) /* posix-style error */ {fprintf(stderr, "%s: %s\n", msg, strerror(code));exit(0); } void dns_error(char *msg) /* dns-style error */ {fprintf(stderr, "%s: DNS error %d\n", msg, h_errno);exit(0); } void app_error(char *msg) /* application error */ {fprintf(stderr, "%s\n", msg);exit(0); } /* $end errorfuns */ /********************************************** Wrappers for Unix process control functions********************************************/ /* $begin forkwrapper */ pid_t Fork(void) {pid_t pid;if ((pid = fork()) < 0)unix_error("Fork error");return pid; } /* $end forkwrapper */ void Execve(const char *filename, char *const argv[], char *const envp[]) {if (execve(filename, argv, envp) < 0)unix_error("Execve error"); } /* $begin wait */ pid_t Wait(int *status) {pid_t pid;if ((pid = wait(status)) < 0)unix_error("Wait error");return pid; } /* $end wait */pid_t Waitpid(pid_t pid, int *iptr, int options) {pid_t retpid;if ((retpid = waitpid(pid, iptr, options)) < 0) unix_error("Waitpid error");return(retpid); } /* $begin kill */ void Kill(pid_t pid, int signum) {int rc;if ((rc = kill(pid, signum)) < 0)unix_error("Kill error"); } /* $end kill */ void Pause() {(void)pause();return; } unsigned int Sleep(unsigned int secs) {unsigned int rc;if ((rc = sleep(secs)) < 0)unix_error("Sleep error");return rc; } unsigned int Alarm(unsigned int seconds) {return alarm(seconds); } void Setpgid(pid_t pid, pid_t pgid) {int rc;if ((rc = setpgid(pid, pgid)) < 0)unix_error("Setpgid error");return; } pid_t Getpgrp(void) {return getpgrp(); } /************************************* Wrappers for Unix signal functions ***********************************/ /* $begin sigaction */ handler_t *Signal(int signum, handler_t *handler) {struct sigaction action, old_action;action.sa_handler = handler; sigemptyset(&action.sa_mask); /* block sigs of type being handled */action.sa_flags = SA_RESTART; /* restart syscalls if possible */if (sigaction(signum, &action, &old_action) < 0)unix_error("Signal error");return (old_action.sa_handler); } /* $end sigaction */ void Sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {if (sigprocmask(how, set, oldset) < 0)unix_error("Sigprocmask error");return; } void Sigemptyset(sigset_t *set) {if (sigemptyset(set) < 0)unix_error("Sigemptyset error");return; } void Sigfillset(sigset_t *set) { if (sigfillset(set) < 0)unix_error("Sigfillset error");return; } void Sigaddset(sigset_t *set, int signum) {if (sigaddset(set, signum) < 0)unix_error("Sigaddset error");return; } void Sigdelset(sigset_t *set, int signum) {if (sigdelset(set, signum) < 0)unix_error("Sigdelset error");return; } int Sigismember(const sigset_t *set, int signum) {int rc;if ((rc = sigismember(set, signum)) < 0)unix_error("Sigismember error");return rc; } /********************************* Wrappers for Unix I/O routines********************************/ int Open(const char *pathname, int flags, mode_t mode) {int rc;if ((rc = open(pathname, flags, mode)) < 0)unix_error("Open error");return rc; } ssize_t Read(int fd, void *buf, size_t count) {ssize_t rc;if ((rc = read(fd, buf, count)) < 0) unix_error("Read error");return rc; } ssize_t Write(int fd, const void *buf, size_t count) {ssize_t rc;if ((rc = write(fd, buf, count)) < 0)unix_error("Write error");return rc; } off_t Lseek(int fildes, off_t offset, int whence) {off_t rc;if ((rc = lseek(fildes, offset, whence)) < 0)unix_error("Lseek error");return rc; } void Close(int fd) {int rc;if ((rc = close(fd)) < 0)unix_error("Close error"); } int Select(int n, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout) {int rc;if ((rc = select(n, readfds, writefds, exceptfds, timeout)) < 0)unix_error("Select error");return rc; } int Dup2(int fd1, int fd2) {int rc;if ((rc = dup2(fd1, fd2)) < 0)unix_error("Dup2 error");return rc; } void Stat(const char *filename, struct stat *buf) {if (stat(filename, buf) < 0)unix_error("Stat error"); } void Fstat(int fd, struct stat *buf) {if (fstat(fd, buf) < 0)unix_error("Fstat error"); } /**************************************** Wrappers for memory mapping functions***************************************/ void *Mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) {void *ptr;if ((ptr = mmap(addr, len, prot, flags, fd, offset)) == ((void *) -1))unix_error("mmap error");return(ptr); } void Munmap(void *start, size_t length) {if (munmap(start, length) < 0)unix_error("munmap error"); } /**************************************************** Wrappers for dynamic storage allocation functions***************************************************/ void *Malloc(size_t size) {void *p;if ((p = malloc(size)) == NULL)unix_error("Malloc error");return p; } void *Realloc(void *ptr, size_t size) {void *p;if ((p = realloc(ptr, size)) == NULL)unix_error("Realloc error");return p; } void *Calloc(size_t nmemb, size_t size) {void *p;if ((p = calloc(nmemb, size)) == NULL)unix_error("Calloc error");return p; } void Free(void *ptr) {free(ptr); } /******************************************* Wrappers for the Standard I/O functions.******************************************/ void Fclose(FILE *fp) {if (fclose(fp) != 0)unix_error("Fclose error"); } FILE *Fdopen(int fd, const char *type) {FILE *fp;if ((fp = fdopen(fd, type)) == NULL)unix_error("Fdopen error");return fp; } char *Fgets(char *ptr, int n, FILE *stream) {char *rptr;if (((rptr = fgets(ptr, n, stream)) == NULL) && ferror(stream))app_error("Fgets error");return rptr; } FILE *Fopen(const char *filename, const char *mode) {FILE *fp;if ((fp = fopen(filename, mode)) == NULL)unix_error("Fopen error");return fp; } void Fputs(const char *ptr, FILE *stream) {if (fputs(ptr, stream) == EOF)unix_error("Fputs error"); } size_t Fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {size_t n;if (((n = fread(ptr, size, nmemb, stream)) < nmemb) && ferror(stream)) unix_error("Fread error");return n; } void Fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {if (fwrite(ptr, size, nmemb, stream) < nmemb)unix_error("Fwrite error"); } /**************************** * Sockets interface wrappers****************************/ int Socket(int domain, int type, int protocol) {int rc;if ((rc = socket(domain, type, protocol)) < 0)unix_error("Socket error");return rc; } void Setsockopt(int s, int level, int optname, const void *optval, int optlen) {int rc;if ((rc = setsockopt(s, level, optname, optval, optlen)) < 0)unix_error("Setsockopt error"); } void Bind(int sockfd, struct sockaddr *my_addr, int addrlen) {int rc;if ((rc = bind(sockfd, my_addr, addrlen)) < 0)unix_error("Bind error"); } void Listen(int s, int backlog) {int rc;if ((rc = listen(s, backlog)) < 0)unix_error("Listen error"); }int Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {int rc;if ((rc = accept(s, addr, addrlen)) < 0)unix_error("Accept error");return rc; } void Connect(int sockfd, struct sockaddr *serv_addr, int addrlen) {int rc;if ((rc = connect(sockfd, serv_addr, addrlen)) < 0)unix_error("Connect error"); } /************************* DNS interface wrappers ***********************/ /* $begin gethostbyname */ struct hostent *Gethostbyname(const char *name) {struct hostent *p;if ((p = gethostbyname(name)) == NULL)dns_error("Gethostbyname error");return p; } /* $end gethostbyname */ struct hostent *Gethostbyaddr(const char *addr, int len, int type) {struct hostent *p;if ((p = gethostbyaddr(addr, len, type)) == NULL)dns_error("Gethostbyaddr error");return p; } /************************************************* Wrappers for Pthreads thread control functions************************************************/ void Pthread_create(pthread_t *tidp, pthread_attr_t *attrp, void * (*routine)(void *), void *argp) {int rc;if ((rc = pthread_create(tidp, attrp, routine, argp)) != 0)posix_error(rc, "Pthread_create error"); } void Pthread_cancel(pthread_t tid) {int rc;if ((rc = pthread_cancel(tid)) != 0)posix_error(rc, "Pthread_cancel error"); } void Pthread_join(pthread_t tid, void **thread_return) {int rc;if ((rc = pthread_join(tid, thread_return)) != 0)posix_error(rc, "Pthread_join error"); } /* $begin detach */ void Pthread_detach(pthread_t tid) {int rc;if ((rc = pthread_detach(tid)) != 0)posix_error(rc, "Pthread_detach error"); } /* $end detach */ void Pthread_exit(void *retval) {pthread_exit(retval); } pthread_t Pthread_self(void) {return pthread_self(); } void Pthread_once(pthread_once_t *once_control, void (*init_function)()) {pthread_once(once_control, init_function); } /******************************** Wrappers for Posix semaphores*******************************/ void Sem_init(sem_t *sem, int pshared, unsigned int value) {if (sem_init(sem, pshared, value) < 0)unix_error("Sem_init error"); } void P(sem_t *sem) {if (sem_wait(sem) < 0)unix_error("P error"); } void V(sem_t *sem) {if (sem_post(sem) < 0)unix_error("V error"); } /********************************************************************** The Rio package - robust I/O functions**********************************************************************/ /** rio_readn - robustly read n bytes (unbuffered)*/ /* $begin rio_readn */ ssize_t rio_readn(int fd, void *usrbuf, size_t n) {size_t nleft = n;ssize_t nread;char *bufp = usrbuf;while (nleft > 0) {if ((nread = read(fd, bufp, nleft)) < 0) {if (errno == EINTR) /* interrupted by sig handler return */nread = 0; /* and call read() again */elsereturn -1; /* errno set by read() */ } else if (nread == 0)break; /* EOF */nleft -= nread;bufp += nread;}return (n - nleft); /* return >= 0 */ } /* $end rio_readn *//** rio_writen - robustly write n bytes (unbuffered)*/ /* $begin rio_writen */ ssize_t rio_writen(int fd, void *usrbuf, size_t n) {size_t nleft = n;ssize_t nwritten;char *bufp = usrbuf;while (nleft > 0) {if ((nwritten = write(fd, bufp, nleft)) <= 0) {if (errno == EINTR) /* interrupted by sig handler return */nwritten = 0; /* and call write() again */elsereturn -1; /* errno set by write() */}nleft -= nwritten;bufp += nwritten;}return n; } /* $end rio_writen */ /* * rio_read - This is a wrapper for the Unix read() function that* transfers min(n, rio_cnt) bytes from an internal buffer to a user* buffer, where n is the number of bytes requested by the user and* rio_cnt is the number of unread bytes in the internal buffer. On* entry, rio_read() refills the internal buffer via a call to* read() if the internal buffer is empty.*/ /* $begin rio_read */ static ssize_t rio_read(rio_t *rp, char *usrbuf, size_t n) {int cnt;while (rp->rio_cnt <= 0) { /* refill if buf is empty */rp->rio_cnt = read(rp->rio_fd, rp->rio_buf, sizeof(rp->rio_buf));if (rp->rio_cnt < 0) {if (errno != EINTR) /* interrupted by sig handler return */return -1;}else if (rp->rio_cnt == 0) /* EOF */return 0;else rp->rio_bufptr = rp->rio_buf; /* reset buffer ptr */}/* Copy min(n, rp->rio_cnt) bytes from internal buf to user buf */cnt = n; if (rp->rio_cnt < n) cnt = rp->rio_cnt;memcpy(usrbuf, rp->rio_bufptr, cnt);rp->rio_bufptr += cnt;rp->rio_cnt -= cnt;return cnt; } /* $end rio_read *//** rio_readinitb - Associate a descriptor with a read buffer and reset buffer*/ /* $begin rio_readinitb */ void rio_readinitb(rio_t *rp, int fd) {rp->rio_fd = fd; rp->rio_cnt = 0; rp->rio_bufptr = rp->rio_buf; } /* $end rio_readinitb */ /** rio_readnb - Robustly read n bytes (buffered)*/ /* $begin rio_readnb */ ssize_t rio_readnb(rio_t *rp, void *usrbuf, size_t n) {size_t nleft = n;ssize_t nread;char *bufp = usrbuf;while (nleft > 0) {if ((nread = rio_read(rp, bufp, nleft)) < 0) {if (errno == EINTR) /* interrupted by sig handler return */nread = 0; /* call read() again */elsereturn -1; /* errno set by read() */ } else if (nread == 0)break; /* EOF */nleft -= nread;bufp += nread;}return (n - nleft); /* return >= 0 */ } /* $end rio_readnb */ /* * rio_readlineb - robustly read a text line (buffered)*/ /* $begin rio_readlineb */ ssize_t rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen) {int n, rc;char c, *bufp = usrbuf;for (n = 1; n < maxlen; n++) { if ((rc = rio_read(rp, &c, 1)) == 1) {*bufp++ = c;if (c == '\n')break;} else if (rc == 0) {if (n == 1)return 0; /* EOF, no data read */elsebreak; /* EOF, some data was read */} elsereturn -1; /* error */}*bufp = 0;return n; } /* $end rio_readlineb *//*********************************** Wrappers for robust I/O routines**********************************/ ssize_t Rio_readn(int fd, void *ptr, size_t nbytes) {ssize_t n;if ((n = rio_readn(fd, ptr, nbytes)) < 0)unix_error("Rio_readn error");return n; } void Rio_writen(int fd, void *usrbuf, size_t n) {if (rio_writen(fd, usrbuf, n) != n)unix_error("Rio_writen error"); } void Rio_readinitb(rio_t *rp, int fd) {rio_readinitb(rp, fd); } ssize_t Rio_readnb(rio_t *rp, void *usrbuf, size_t n) {ssize_t rc;if ((rc = rio_readnb(rp, usrbuf, n)) < 0)unix_error("Rio_readnb error");return rc; } ssize_t Rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen) {ssize_t rc;if ((rc = rio_readlineb(rp, usrbuf, maxlen)) < 0)unix_error("Rio_readlineb error");return rc; } /******************************** * Client/server helper functions********************************/ /** open_clientfd - open connection to server at <hostname, port> * and return a socket descriptor ready for reading and writing.* Returns -1 and sets errno on Unix error. * Returns -2 and sets h_errno on DNS (gethostbyname) error.*/ /* $begin open_clientfd */ int open_clientfd(char *hostname, int port) {int clientfd;struct hostent *hp;struct sockaddr_in serveraddr;if ((clientfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)return -1; /* check errno for cause of error *//* Fill in the server's IP address and port */if ((hp = gethostbyname(hostname)) == NULL)return -2; /* check h_errno for cause of error */bzero((char *) &serveraddr, sizeof(serveraddr));serveraddr.sin_family = AF_INET;bcopy((char *)hp->h_addr_list[0], (char *)&serveraddr.sin_addr.s_addr, hp->h_length);serveraddr.sin_port = htons(port);/* Establish a connection with the server */if (connect(clientfd, (SA *) &serveraddr, sizeof(serveraddr)) < 0)return -1;return clientfd; } /* $end open_clientfd */ /* * open_listenfd - open and return a listening socket on port* Returns -1 and sets errno on Unix error.*/ /* $begin open_listenfd */ int open_listenfd(int port) {int listenfd, optval=1;struct sockaddr_in serveraddr;/* Create a socket descriptor */if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)return -1;/* Eliminates "Address already in use" error from bind. */if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval , sizeof(int)) < 0)return -1;/* Listenfd will be an endpoint for all requests to porton any IP address for this host */bzero((char *) &serveraddr, sizeof(serveraddr));serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); serveraddr.sin_port = htons((unsigned short)port); if (bind(listenfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0)return -1;/* Make it a listening socket ready to accept connection requests */if (listen(listenfd, LISTENQ) < 0)return -1;return listenfd; } /* $end open_listenfd */ /******************************************* Wrappers for the client/server helper routines ******************************************/ int Open_clientfd(char *hostname, int port) {int rc;if ((rc = open_clientfd(hostname, port)) < 0) {if (rc == -1)unix_error("Open_clientfd Unix error");else dns_error("Open_clientfd DNS error");}return rc; } int Open_listenfd(int port) {int rc;if ((rc = open_listenfd(port)) < 0)unix_error("Open_listenfd error");return rc; } /* $end csapp.c */

返回目錄

三、代碼托管與統計


****
代碼托管

返回目錄

四、學習進度條


代碼行數(新增/累積)博客量(新增/累積)學習時間(新增/累積)重要成長
目標5000行30篇400小時
第一周87/872/220/20
第二周71/1581/312/32
第三周100/2582/513/45
第四周3265/97502/715/60
第五周282/97861/88/68
第六周1980/139962/108/76

嘗試一下記錄「計劃學習時間」和「實際學習時間」,到期末看看能不能改進自己的計劃能力。這個工作學習中很重要,也很有用。
耗時估計的公式
:Y=X+X/N ,Y=X-X/N,訓練次數多了,X、Y就接近了。

參考:軟件工程軟件的估計為什么這么難,軟件工程 估計方法

  • 計劃學習時間:8小時

  • 實際學習時間:8小時

  • 改進情況:

(有空多看看現代軟件工程 課件
軟件工程師能力自我評價表)

返回目錄

五、參考資料


  • 《深入理解計算機系統V3》學習指導
  • Linux 基礎入門(新版)_Linux_實驗樓 - 實驗樓

返回目錄

轉載于:https://www.cnblogs.com/musea/p/9875423.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的2018-2019-1 20165226 《信息安全系统设计基础》第6周学习总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲免费综合 | 日本不卡一区在线观看 | 91免费小视频 | 国产尤物在线 | 日本黄色片在线播放 | 91久久精品国产 | 亚洲AV无码精品黑人黑人 | 国产91丝袜| 欧美乱大交 | 久久久久久久久久久国产精品 | 毛片网站免费 | 欧美日韩精 | www.射| 欧美激情天堂 | 日本成人在线一区 | 亚洲第一天堂在线观看 | 久久久久成人精品无码中文字幕 | 国产av无码专区亚洲a∨毛片 | 华丽的外出在线 | 老熟妇仑乱一区二区视频 | 亚洲激情五月婷婷 | 精品国产乱码久久久久久久 | 九九五月天 | 欧美一级爽aaaaa大片 | 精品一区二区三区av | 依人综合网 | 美女黄视频大全 | 久久久久久久久影院 | 三上悠亚人妻中文字幕在线 | 我们好看的2018视频在线观看 | 欧美黄色性生活 | 在线观看视频91 | 免费网站黄色 | 国产美女视频91 | 亚洲另类色综合网站 | 欧美区亚洲区 | 中国国语农村大片 | 青青青手机在线视频 | 亚洲高清中文字幕 | 97国产在线视频 | 五月天久久婷婷 | 日韩视频一区二区在线观看 | 国产操| 国产伦精品一区二区三区照片91 | 999国内精品永久免费视频 | 无码少妇一级AV片在线观看 | 农村激情伦hxvideos | 天天综合精品 | 日批视频免费在线观看 | 毛茸茸free性熟hd | 搞黄网站在线观看 | 亚洲av成人一区二区 | 操碰视频在线 | 黄色三级视频网站 | 欧美性激情 | 亚洲欧美日本另类 | 日本久操 | 国产一页 | 精品午夜久久久 | 日韩一二三区 | 国产精品福利一区二区三区 | 国产毛毛片 | 色狠狠一区二区 | 欧美在线一区二区视频 | 欧美一区二区激情视频 | 国产ts三人妖大战直男 | 亚洲国产爱 | 欧美日韩亚洲精品一区二区 | 日本一区二区在线观看视频 | 99精品国产一区 | 成人天堂噜噜噜 | 国产亚洲精品av | 91片黄在线观 | 欧美日韩1区2区3区 亚洲日本精品视频 | 国产成人综合在线观看 | 武林美妇肉伦娇喘呻吟 | 最新国产在线视频 | 亚洲高清在线一区 | 国产污视频在线观看 | 最好看的mv中文字幕国语电影 | 黄色网炮| 东京久久久 | 在线播放国产一区 | 精品二区在线观看 | 精品久久伊人 | 国产一级做a爰片在线看免费 | 久久久久久久久久久久久久久久久久 | 毛片在线免费观看视频 | 国产精选中文字幕 | 欧美a在线播放 | 中文字幕在线观看第一页 | 成人午夜在线播放 | 伊人99| 日韩欧美久久精品 | 欧美88av | 黄色片成人 | 极品videosvideo喷水 | 无码人妻精品一区二区三区蜜桃91 | 在线黄色大片 |