Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed Jun 25, 2019
1 parent 986f1d2 commit b5b15eb
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/notes/Git.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ Git 的版本库有一个称为 Stage 的暂存区以及最后的 History 版本
- git reset -- files 使用当前分支上的修改覆盖暂存区,用来撤销最后git add files
- git checkout -- files 使用暂存区的修改覆盖工作目录,用来撤销本地修改

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/603dbb49-dac5-4825-9694-5f1d65cefd44.png" width="320px"> </div><br>
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/72ee7e9a-194d-42e9-b4d7-29c23417ca18.png" width="320px"> </div><br>

可以跳过暂存区域直接从分支中取出修改,或者直接提交修改到分支中。

- git commit -a 直接把所有文件的修改添加到暂存区然后执行提交
- git checkout HEAD -- files 取出最后次修改,可以用来进行回滚操作

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/265bab88-7be9-44c5-a33f-f93d9882c096.png" width="500px"> </div><br>
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a4a0a6e6-386b-4bfa-b899-ec33d3310f3e.png" width="500px"> </div><br>

# 分支实现

Expand Down
25 changes: 20 additions & 5 deletions docs/notes/Socket.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ select/poll/epoll 都是 I/O 多路复用的具体实现,select 出现的最
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
```

有三种类型的描述符类型:readsetwritesetexceptset,分别对应读、写、异常条件的描述符集合。fd_set 使用数组实现,数组大小使用 FD_SETSIZE 定义
select 允许应用程序监视组文件描述符,等待个或者多个描述符成为就绪状态,从而完成 I/O 操作

timeout 为超时参数,调用 select直阻塞直到有描述符的事件到达或者等待的时间超过 timeout
- fd_set 使用数组实现,数组大小使用 FD_SETSIZE 定义,所以只能监听少于 FD_SETSIZE 数量的描述符。有三种类型的描述符类型:readsetwritesetexceptset,分别对应读、写、异常条件的描述符集合

成功调用返回结果大于 0,出错返回结果为 -1,超时返回结果为 0
- timeout 为超时参数,调用 select直阻塞直到有描述符的事件到达或者等待的时间超过 timeout

- 成功调用返回结果大于 0,出错返回结果为 -1,超时返回结果为 0

```c
fd_set fd_in, fd_out;
Expand Down Expand Up @@ -154,7 +156,18 @@ else
int poll(struct pollfd *fds, unsigned int nfds, int timeout);
```

pollfd 使用链表实现。
poll 的功能与 select 类似,也是等待组描述符中的个成为就绪状态。

poll 中的描述符是 pollfd 类型的数组,pollfd 的定义如下:

```c
struct pollfd {
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
```


```c
// The structure for two events
Expand Down Expand Up @@ -195,7 +208,7 @@ else
selectpoll 的功能基本相同,不过在些实现细节上有所不同。

- select 会修改描述符,而 poll 不会;
- select 的描述符类型使用数组实现,FD_SETSIZE 大小默认为 1024,因此默认只能监听 1024 个描述符。如果要监听更多描述符的话,需要修改 FD_SETSIZE 之后重新编译;而 poll 的描述符类型使用链表实现,没有描述符数量的限制;
- select 的描述符类型使用数组实现,FD_SETSIZE 大小默认为 1024,因此默认只能监听 1024 个描述符。如果要监听更多描述符的话,需要修改 FD_SETSIZE 之后重新编译;而 poll 没有描述符数量的限制;
- poll 提供了更多的事件类型,并且对描述符的重复利用上比 select 高。
- 如果个线程对某个描述符调用了 select 或者 poll,另个线程关闭了该描述符,会导致调用结果不确定。

Expand Down Expand Up @@ -315,6 +328,8 @@ poll 没有最大描述符数量的限制,如果平台支持并且对实时性
# 参考资料

- Stevens W R, Fenner B, Rudoff A M. UNIX network programming[M]. Addison-Wesley Professional, 2004.
- http://man7.org/linux/man-pages/man2/select.2.html
- http://man7.org/linux/man-pages/man2/poll.2.html
- [Boost application performance using asynchronous I/O](https://www.ibm.com/developerworks/linux/library/l-async/)
- [Synchronous and Asynchronous I/O](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365683(v=vs.85).aspx)
- [Linux IO 模式及 selectpollepoll 详解](https://segmentfault.com/a/1190000003063859)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions notes/Git.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ Git 的版本库有一个称为 Stage 的暂存区以及最后的 History 版本
- git reset -- files 使用当前分支上的修改覆盖暂存区,用来撤销最后git add files
- git checkout -- files 使用暂存区的修改覆盖工作目录,用来撤销本地修改

<div align="center"> <img src="pics/603dbb49-dac5-4825-9694-5f1d65cefd44.png" width="320px"> </div><br>
<div align="center"> <img src="pics/72ee7e9a-194d-42e9-b4d7-29c23417ca18.png" width="320px"> </div><br>

可以跳过暂存区域直接从分支中取出修改,或者直接提交修改到分支中。

- git commit -a 直接把所有文件的修改添加到暂存区然后执行提交
- git checkout HEAD -- files 取出最后次修改,可以用来进行回滚操作

<div align="center"> <img src="pics/265bab88-7be9-44c5-a33f-f93d9882c096.png" width="500px"> </div><br>
<div align="center"> <img src="pics/a4a0a6e6-386b-4bfa-b899-ec33d3310f3e.png" width="500px"> </div><br>

# 分支实现

Expand Down
1 change: 0 additions & 1 deletion notes/Java 并发.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ main() 属于非守护线程。
public static void main(String[] args) {
Thread thread = new Thread(new MyRunnable());
thread.setDaemon(true);
thread.start();
}
```

Expand Down
25 changes: 20 additions & 5 deletions notes/Socket.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ select/poll/epoll 都是 I/O 多路复用的具体实现,select 出现的最
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
```

有三种类型的描述符类型:readsetwritesetexceptset,分别对应读、写、异常条件的描述符集合。fd_set 使用数组实现,数组大小使用 FD_SETSIZE 定义
select 允许应用程序监视组文件描述符,等待个或者多个描述符成为就绪状态,从而完成 I/O 操作

timeout 为超时参数,调用 select直阻塞直到有描述符的事件到达或者等待的时间超过 timeout
- fd_set 使用数组实现,数组大小使用 FD_SETSIZE 定义,所以只能监听少于 FD_SETSIZE 数量的描述符。有三种类型的描述符类型:readsetwritesetexceptset,分别对应读、写、异常条件的描述符集合

成功调用返回结果大于 0,出错返回结果为 -1,超时返回结果为 0
- timeout 为超时参数,调用 select直阻塞直到有描述符的事件到达或者等待的时间超过 timeout

- 成功调用返回结果大于 0,出错返回结果为 -1,超时返回结果为 0

```c
fd_set fd_in, fd_out;
Expand Down Expand Up @@ -154,7 +156,18 @@ else
int poll(struct pollfd *fds, unsigned int nfds, int timeout);
```

pollfd 使用链表实现。
poll 的功能与 select 类似,也是等待组描述符中的个成为就绪状态。

poll 中的描述符是 pollfd 类型的数组,pollfd 的定义如下:

```c
struct pollfd {
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
```


```c
// The structure for two events
Expand Down Expand Up @@ -195,7 +208,7 @@ else
selectpoll 的功能基本相同,不过在些实现细节上有所不同。

- select 会修改描述符,而 poll 不会;
- select 的描述符类型使用数组实现,FD_SETSIZE 大小默认为 1024,因此默认只能监听 1024 个描述符。如果要监听更多描述符的话,需要修改 FD_SETSIZE 之后重新编译;而 poll 的描述符类型使用链表实现,没有描述符数量的限制;
- select 的描述符类型使用数组实现,FD_SETSIZE 大小默认为 1024,因此默认只能监听 1024 个描述符。如果要监听更多描述符的话,需要修改 FD_SETSIZE 之后重新编译;而 poll 没有描述符数量的限制;
- poll 提供了更多的事件类型,并且对描述符的重复利用上比 select 高。
- 如果个线程对某个描述符调用了 select 或者 poll,另个线程关闭了该描述符,会导致调用结果不确定。

Expand Down Expand Up @@ -315,6 +328,8 @@ poll 没有最大描述符数量的限制,如果平台支持并且对实时性
# 参考资料

- Stevens W R, Fenner B, Rudoff A M. UNIX network programming[M]. Addison-Wesley Professional, 2004.
- http://man7.org/linux/man-pages/man2/select.2.html
- http://man7.org/linux/man-pages/man2/poll.2.html
- [Boost application performance using asynchronous I/O](https://www.ibm.com/developerworks/linux/library/l-async/)
- [Synchronous and Asynchronous I/O](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365683(v=vs.85).aspx)
- [Linux IO 模式及 selectpollepoll 详解](https://segmentfault.com/a/1190000003063859)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b5b15eb

Please sign in to comment.