Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NandanaDV committed Oct 14, 2024
2 parents cb8498c + e384bda commit 4c261b7
Show file tree
Hide file tree
Showing 25 changed files with 1,806 additions and 310 deletions.
16 changes: 8 additions & 8 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ export default defineConfig({
link: '/guides/resources/tcp-ip-model',
},
{ text: 'TCP Socket Programming', link: '/guides/resources/tcp-socket-programming' },
{ text: 'Sockets', link: '/guides/resources/sockets' },
{ text: 'UDP Socket Programming', link: '/guides/resources/udp-socket-programming' },
{ text: 'Process and Threads', link: '/guides/resources/process-and-threads' },
{ text: 'System Calls', link: '/guides/resources/system-calls' },
{
text: 'Introduction to Linux epoll',
link: '/guides/resources/introduction-to-linux-epoll',
},
{
text: 'Linux epoll tutorial',
link: '/guides/resources/linux-epoll-tutorial',
},
{
text: 'Blocking & Non-Blocking Sockets',
link: '/guides/resources/blocking-and-non-blocking-sockets',
},
{ text: 'HTTP', link: '/guides/resources/http' },
{ text: 'UDP', link: '/guides/resources/udp' },
{ text: 'Multi-threading', link: '/guides/resources/multi-threading' },
{ text: 'Fork', link: '/guides/resources/fork' },

// { text: 'Internet Protocol (IP)', link: '/guides/resources/ip' },
// { text: 'File descriptors', link: '/guides/resources/file-descriptors' },
Expand Down Expand Up @@ -99,14 +102,11 @@ export default defineConfig({
{
text: 'Stage 3: UDP Multi-threading',
link: '/roadmap/phase-0/stage-3',
// text: 'Stage 3: Linux epoll',
// link: '/roadmap/phase-0/stage-3',
},
{
text: 'Stage 4: Linux epoll',
link: '/roadmap/phase-0/stage-4',
// text: 'Stage 4: UDP Multi-threading',
// link: '/roadmap/phase-0/stage-4',

},
{
text: 'Stage 5: TCP Proxy',
Expand Down
Binary file added docs/assets/resources/fork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/resources/pcb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/resources/segments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/resources/tcb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/resources/thread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/resources/udp-ip-packet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions docs/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ The guides feature supplementary documentation intended for your reference as yo

✅ Reviewed
🟡 To be reviewed
⚪ Partially reviewed

-[Architecture](/guides/resources/architecture)
-[Coding Conventions](/guides/resources/coding-conventions)
-[TCP/IP Model](/guides/resources/tcp-ip-model)
<!-- - ✅ [TCP](/guides/resources/tcp) -->
<!-- - ✅ [Sockets](/guides/resources/sockets) -->
-[TCP Socket Programming](/guides/resources/tcp-socket-programming)
- 🟡 [UDP Socket Programming](/guides/resources/udp-socket-programming)
-[Process and Threads](/guides/resources/process-and-threads)
-[System Calls](/guides/resources/system-calls)
-[Linux epoll](/guides/resources/introduction-to-linux-epoll)
- 🟡 [Linux epoll tutorial](/guides/resources/linux-epoll-tutorial)
- 🟡 [Blocking & Non-Blocking Sockets](/guides/resources/blocking-and-non-blocking-sockets)
- 🟡 [TCP Socket Programming](/guides/resources/tcp-socket-programming)
- 🟡 [HTTP](/guides/resources/http)
- 🟡 [UDP](/guides/resources/udp)
- 🟡 [Multi-threading](/guides/resources/multi-threading)
- 🟡 [Fork()](/guides/resources/fork)


## References

Expand Down
13 changes: 0 additions & 13 deletions docs/guides/resources/fork.md

This file was deleted.

38 changes: 19 additions & 19 deletions docs/guides/resources/linux-epoll-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## epoll

*epoll* is an I/O event notification mechanism widely being used in modern web servers like Nginx. *epoll* stands for event poll and it is a Linux specific construct.
*epoll* is an I/O event notification mechanism widely being used in modern web servers like [Nginx](https://en.wikipedia.org/wiki/Nginx). *epoll* stands for event poll and it is a Linux specific construct.

Epoll refers to a kernel data structure. It maintains a list of file descriptors, which allows a process to get notifications whenever an I/O event is possible on any of these file descriptors. epoll_create(), epoll_ctl() and epoll_wait() are the three main system calls that deal with the implementation of epoll. All these system calls are included in the sys/epoll.h header file.
Epoll refers to a kernel data structure. It maintains a list of file descriptors, which allows a process to get notifications whenever an I/O event is possible on any of these file descriptors. `epoll_create()`, `epoll_ctl()` and `epoll_wait()` are the three main system calls that deal with the implementation of epoll. All these system calls are included in the `<sys/epoll.h>` header file.

## epoll_create()
## `epoll_create()`

epoll_create() is the system call used to create an epoll instance. An epoll instance is identified by a file descriptor in linux. The epoll_create() returns a file descriptor that identify the newly created kernel data structure.
`epoll_create()` is the system call used to create an epoll instance. An epoll instance is identified by a file descriptor in linux. The `epoll_create()` returns a file descriptor that identify the newly created kernel data structure.

```c
#include <sys/epoll.h>
Expand All @@ -17,31 +17,31 @@ int epoll_create(int size);
**Arguments**
**size** - This is the only argument for epoll_create(). It is of integer type. It refers to the number of file descriptors that the process wants to monitor. The kernel decides the size required for the epoll instance(data structure) according to the value in size.
**size** - This is the only argument for `epoll_create(`). It is of integer type. It refers to the number of file descriptors that the process wants to monitor. The kernel decides the size required for the epoll instance(data structure) according to the value in size.
**Return value**
epoll_create() returns an integer which refers to the file descriptor of the created epoll instance.
`epoll_create()` returns an integer which refers to the file descriptor of the created epoll instance.
### epoll_create1()
### `epoll_create1()`
This system call is also used to create an epoll instance similar to epoll_create(), but the arguments differ.
This system call is also used to create an epoll instance similar to `epoll_create()`, but the arguments differ.
```c
int epoll_create1(int flags)
```

Here the flags can be either 0 or EPOLL_CLOEXEC
Here the flags can be either `0` or `EPOLL_CLOEXEC`

if the flag is set to zero, this function behaves same as epoll_create()
if the flag is set to zero, this function behaves same as `epoll_create()`

when the flag is set to EPOLL_CLOEXEC, whenever a child process is forked from the current process it closes the epoll file descriptor in the child before starting its execution. So only the current process will have access to the epoll instance.
when the flag is set to `EPOLL_CLOEXEC`, whenever a child process is forked from the current process it closes the epoll file descriptor in the child before starting its execution. So only the current process will have access to the epoll instance.

Since epoll instance is treated as a file descriptor, we use the close() system call in unistd.h header file to close an epoll instance.
Since epoll instance is treated as a file descriptor, we use the `close()` system call in `<unistd.h>` header file to close an epoll instance.

## epoll_ctl()
## `epoll_ctl()`

An epoll instance can maintain a list of file descriptors that has to be monitored. All file descriptors registered with an epoll instance is collectively referred to as epoll list or interest list. Whenever any of the file descriptors become ready for I/O operations, they are added to the ready list. Ready list is a subset of interest list. epoll_ctl() system call is used to add, modify or delete file descriptors to be monitored in the interest list of epoll.
An epoll instance can maintain a list of file descriptors that has to be monitored. All file descriptors registered with an epoll instance is collectively referred to as epoll list or **interest list**. Whenever any of the file descriptors become ready for I/O operations, they are added to the **ready list**. Ready list is a subset of interest list. `epoll_ctl()` system call is used to add, modify or delete file descriptors to be monitored in the interest list of epoll.

```c
#include<sys/epoll.h>
Expand All @@ -62,7 +62,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
4. **event** - It is of epoll_event type.
`epoll_event` structure is included in the `sys/epoll.h` header. The structure of epoll_event is shown below.
`epoll_event` structure is included in the `<sys/epoll.h>` header. The structure of `epoll_event` is shown below.
```c
struct epoll_event
Expand Down Expand Up @@ -94,7 +94,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);

**Return Value -** when successful, epol_ctl returns zero. When an error occurs, it returns -1 and errno is set to indicate the error.

## epoll_wait()
## `epoll_wait()`

This system call is used to notify the process, when some event has occurred on the interest list of the epoll instance. It blocks the process until any of the descriptors being monitored becomes ready for I/O events.

Expand All @@ -106,9 +106,9 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
**Arguments**
1. **epfd** - It is of type integer. It is the file descriptor that refers to the epoll instance.
2. **events** - It is an array of `epoll_event` structures. It is allocated by the calling process. The values in this array is filled when epoll_wait returns. It will have the list of file descriptors that are in ready state.
3. **maxevents** - ****It is of integer type. It refers to the length of events array.
4. **timeout** - It is of integer type. It refers to the time in milliseconds for which epoll_wait() will block. If it is set to 0, epoll_wait() will not block and if it is set to -1, it will block forever.
2. **events** - It is an array of `epoll_event` structures. It is allocated by the calling process. The values in this array is filled when `epoll_wait` returns. It will have the list of file descriptors that are in ready state.
3. **maxevents** - It is of integer type. It refers to the length of events array.
4. **timeout** - It is of integer type. It refers to the time in milliseconds for which `epoll_wait()` will block. If it is set to 0, `epoll_wait()` will not block and if it is set to -1, it will block forever.
Expand Down
Loading

0 comments on commit 4c261b7

Please sign in to comment.