You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/roadmap/phase-1/stage-10.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,9 +34,9 @@ Along with modifying the existing modules to enable data transfer through pipes,
34
34
35
35
Three new structs are introduced here. The `xps_pipe_s` struct includes the buffer and the maximum threshold. The `xps_pipe_source_s` and `xps_pipe_sink_s` structs includes the `ready`/`active` flags and callback functions. Earlier the callback functions were called based on the `read_ready` / `write_ready` flags of connection , here it would be based on the status of source/sink and whether the pipe is readable/writable. A pipe is readable if the length of `buff_list` greater than `0` and writable if its length less than the maximum threshold.
36
36
37
-
The callback functions in `connection.c` are modified to ensure the working of source-sink system. The `connection_source_handler()` reads the data using `recv()` and writes it to pipe, whereas the `connection_sink_handler()` reads the data from pipe and `send()`.
37
+
The callback functions in `xps_connection.c` are modified to ensure the working of source-sink system. The `connection_source_handler()` reads the data using `recv()` and writes it to pipe, whereas the `connection_sink_handler()` reads the data from pipe and `send()`.
38
38
39
-
Here, the timeout in the `epollwait()` is set according to the existence of ready pipes. A ready pipe indicates that some operation has to be done on that - write into, read from , destroy. The availability of ready pipe leads to the timeout being set to 0, which results in a non-blocking call as discussed earlier.
39
+
Here, the timeout in the `epoll_wait()` is set according to the existence of ready pipes. A ready pipe indicates that some operation has to be done on that - write into, read from , destroy. The availability of ready pipe leads to the timeout being set to 0, which results in a non-blocking call as discussed earlier.
40
40
41
41
In Stage 6, we have discussed the issue of accumulating nulls in the events,connections and listeners list, here we would be filtering those.
- `handle_epoll_events()` - Replaces the existing `xps_loop_run()`, this function would be invoked from the new `xps_loop_run()`. It iterates thorough the events and corresponding call back functions are called based on epoll notification. This is added to simplify the new `xps_loop_run()`.
785
+
- `handle_epoll_events()` - Replaces the epoll events iteration logic from `xps_loop_run()`, this function would be invoked from the new `xps_loop_run()`. It iterates through the events and corresponding call back functions are called based on epoll notification. This is added to simplify the new `xps_loop_run()`.
Copy file name to clipboardExpand all lines: docs/roadmap/phase-1/stage-12.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ Also declare the newly created function in utility.h
106
106
107
107
### `xps_file.h`
108
108
109
-
The code below has the contents of the header file for `xps_file`. Have a look at it and make a copy of it in your codebase.
109
+
The code below has the contents of the header file for `xps_file.c`. Have a look at it and make a copy of it in your codebase.
110
110
111
111
:::details **expserver/src/disk/xps_file.h**
112
112
@@ -225,7 +225,7 @@ Several file system-related C standard library functions are used to handle file
225
225
226
226
`errno` determines the specific error when an operation fails. In case of `fopen()`, `EACCES` indicates a permission denied error and `ENOENT` indicates the specified file or directory doesn't exist.
227
227
228
-
The functions in xps_file.c are given below:
228
+
The functions in `xps_file.c` are given below:
229
229
230
230
1.**`xps_file_create()`**
231
231
@@ -362,16 +362,16 @@ The second struct is for storing the key-value pairs of mime extensions and mime
362
362
363
363
## `xps_listener` Module - Modifications
364
364
365
-
### `listener.c`
365
+
### `xps_listener.c`
366
366
367
367
As we have to serve file for the incoming connections on port 8002, the `listener_connection_handler` function has to be modified. The `xps_file_create` function is invoked for opening the file and creating a `xps_file_s` instance for it. The path of file to be opened is specified in the argument. Then pipe is created with the source that is attached to the file instead of that attached to connection.
@@ -669,6 +669,10 @@ Another major change is seen in how/who calls the [callback functions](<https://
669
669
670
670
Now we pass the callback functions and pointer to the instance when calling `xps_loop_attach()`.
671
671
672
+
:::tip NOTE
673
+
We have renamed `xps_listener_connection_handler` to `listener_connection_handler` and `xps_connection_read_handler` to `connection_read_handler` as these two functions are no longer global.
/* same code from xps_listener_connection_handler() */
704
+
/* same code logic from xps_listener_connection_handler() */
701
705
702
706
}
703
707
```
@@ -799,7 +803,6 @@ Since we did not modify the functionality of the server, this milestone will is
799
803
#include <netdb.h>
800
804
#include <netinet/in.h>
801
805
#include <stdio.h>
802
-
#include <stdlib.h>
803
806
#include <string.h>
804
807
#include <sys/socket.h>
805
808
#include <sys/types.h>
@@ -827,7 +830,7 @@ Since we did not modify the functionality of the server, this milestone will is
827
830
return -1;
828
831
}
829
832
830
-
if (connect(sock, (struct sockaddr* )&serv_addr, sizeof(serv_addr)) < 0) {
833
+
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
831
834
perror("Connection failed");
832
835
return -1;
833
836
}
@@ -875,7 +878,7 @@ Since we did not modify the functionality of the server, this milestone will is
875
878
876
879
**What is going on here?**
877
880
878
-
The `sender` only sends data to eXpServer. It does not `recv()` data. Thus, when eXpServer is trying to send the reversed string back, it is not getting received. This will cause the kernel buffer to fill up. When the kernel buffer is full the call to `send()` will block the process as we are dealing with blocking network sockets. The process is blocked till the data in the kernel buffer is cleared. However this will not happen as `sender` does not receive any data. Thus the eXpServer process will block leading to no more connections being served.
881
+
The `sender` only sends data to eXpServer. It does not `recv()` data. Thus, when eXpServer is trying to send the reversed string back, it is not getting received. This will cause the kernel buffer to fill up. When the kernel buffer is full, the call to `send()` will block the process as we are dealing with blocking network sockets. The process is blocked till the data in the kernel buffer is cleared. However this will not happen as `sender` does not receive any data. Thus the eXpServer process will block leading to no more connections being served.
879
882
880
883
In a real life situation where the rate at which eXpServer is writing to a TCP socket is more than the rate at which data is received by the TCP client, the kernel buffer can fill up resulting in the server process being blocked intermittently. This leads to inefficient serving of connections.
Copy file name to clipboardExpand all lines: docs/roadmap/phase-1/stage-8.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -204,7 +204,7 @@ Make necessary changes in `xps_loop.c`. Here are a few hints:
204
204
### Modifications to `xps_connection` Module
205
205
206
206
- Similar to `connection_loop_read_handler()`, add `connection_loop_write_handler()` and `connection_loop_close_handler()` in `xps_connection.c` .
207
-
- In `connection_close_handler()` destroy the connection instance.
207
+
- In `connection_loop_close_handler()` destroy the connection instance.
208
208
- Currently in `connection_loop_read_handler()` we `recv()` from the connection socket, reverse the string and `send()` it back. However, from now on `connection_loop_write_handler()` will be invoked when the socket is available to be written to. Hence, `send()` should be invoked within `connection_loop_write_handler()` .
209
209
- Therefore, we need to buffer the reversed strings somewhere till it is ready to be sent. For that we will use an `xps_buffer_list` .
Initialize `send_handler` and `recv_handler` fields of the `xps_connection_s` structure in the `xps_connection_create` function using `connection_read_handler` and `connection_write_handler` callbacks .
119
+
Initialize `send_handler` and `recv_handler` fields of the `xps_connection_s` structure in the `xps_connection_create` function using `connection_write_handler` and `connection_read_handler` callbacks respectively.
120
120
121
121
To enable epoll edge triggering mode we have to set the EPOLLET flag. EPOLLET flag is used to explicitly request the epoll to notify only when an FD changes its state. We have to pass EPOLLET along with EPOLLIN and EPOLLOUT flags in `xps_loop_attach` .
0 commit comments