Skip to content

Commit 392d185

Browse files
authored
Merge pull request #10 from Shibin-Ez/master
Minor corrections on Roadmap till stage 12
2 parents ac73b91 + c80e957 commit 392d185

7 files changed

Lines changed: 22 additions & 23 deletions

File tree

docs/roadmap/phase-1/stage-10.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Along with modifying the existing modules to enable data transfer through pipes,
3434

3535
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.
3636

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()`.
3838

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.
4040

4141
In Stage 6, we have discussed the issue of accumulating nulls in the events,connections and listeners list, here we would be filtering those.
4242

@@ -782,7 +782,7 @@ void filter_nulls(xps_core_t *core) {
782782
```
783783
:::
784784
785-
- `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()`.
786786
::: details **expserver/src/core/xps_loop.c -** `handle_epoll_events()`
787787
788788
```c

docs/roadmap/phase-1/stage-11.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ void listener_connection_handler(void *ptr) {
101101
// Creating connection instance
102102
...
103103
104-
// TEMP
104+
// Handle connection based on listener port (upstream or direct)
105105
if (listener->port == 8001) {
106106
107107
/* create upstream connection */
108108
/*create pipe connection to client source and upstream sink for the listener*/
109109
/*create pipe connection to upstream source and client sink for the listener*/
110110
} else {
111-
/* same as previous stages*/
111+
/* same as previous stages*/
112112
113113
}
114114

docs/roadmap/phase-1/stage-12.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Also declare the newly created function in utility.h
106106
107107
### `xps_file.h`
108108
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.
110110
111111
:::details **expserver/src/disk/xps_file.h**
112112
@@ -225,7 +225,7 @@ Several file system-related C standard library functions are used to handle file
225225

226226
`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.
227227

228-
The functions in xps_file.c are given below:
228+
The functions in `xps_file.c` are given below:
229229

230230
1. **`xps_file_create()`**
231231

@@ -362,16 +362,16 @@ The second struct is for storing the key-value pairs of mime extensions and mime
362362

363363
## `xps_listener` Module - Modifications
364364

365-
### `listener.c`
365+
### `xps_listener.c`
366366

367367
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.
368368

369369
```c
370-
if (listener->port == 8001) {
370+
if (listener->port == 8001) {
371371
....
372372
} else if (listener->port == 8002) {// [!code ++]
373373
int error;// [!code ++]
374-
xps_file_t *file = xps_file_create(listener->core, "../public/sample.txt", &error);// [!code ++]
374+
xps_file_t *file = xps_file_create(listener->core, "public/sample.txt", &error);// [!code ++]
375375
xps_pipe_create(listener->core, DEFAULT_PIPE_BUFF_THRESH, file->source, client->sink);// [!code ++]
376376
} else {
377377
...

docs/roadmap/phase-1/stage-6.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ struct xps_connection_s;
8383
typedef struct xps_listener_s xps_listener_t;
8484
typedef struct xps_connection_s xps_connection_t;
8585

86-
// Function typedefs
87-
typedef void (*xps_handler_t)(void *ptr);
88-
8986
// Temporary declarations
9087
extern vec_void_t listeners;
9188
extern vec_void_t connections;
@@ -718,7 +715,6 @@ After compiling, it should give an output file named `xps`. Start eXpServer usin
718715
[INFO] main() : Server listening on port 8001
719716
[INFO] main() : Server listening on port 8002
720717
[INFO] main() : Server listening on port 8003
721-
[INFO] main() : Server listening on port 8004
722718
```
723719

724720
::: tip NOTE

docs/roadmap/phase-1/stage-7.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ void xps_loop_run(xps_loop_t *loop) {
421421
if (curr_epoll_event.events & EPOLLIN) {
422422
logger(LOG_DEBUG, "handle_epoll_events()", "EVENT / read");
423423
if (curr_event->read_cb != NULL)
424-
// Pass the ptr from loop_event_t to the callback
424+
// Pass the ptr from loop_event_t as a parameter to the callback
425425
curr_event->read_cb(/* fill this */);
426426
}
427427
}
@@ -644,8 +644,8 @@ struct xps_connection_s {
644644
char *remote_ip;
645645
};
646646

647-
xps_connection_t *xps_connection_create(int epoll_fd, int sock_fd, xps_listener_t *listener); // [!code --]
648-
xps_connection_t *xps_connection_create(xps_core_t *core, u_int sock_fd, xps_listener_t *listener);// [!code ++]
647+
xps_connection_t *xps_connection_create(int epoll_fd, int sock_fd); // [!code --]
648+
xps_connection_t *xps_connection_create(xps_core_t *core, u_int sock_fd);// [!code ++]
649649
void xps_connection_destroy(xps_connection_t *connection);
650650
void xps_connection_read_handler(xps_connection_t *connection); // [!code --]
651651

@@ -669,6 +669,10 @@ Another major change is seen in how/who calls the [callback functions](<https://
669669

670670
Now we pass the callback functions and pointer to the instance when calling `xps_loop_attach()`.
671671

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.
674+
:::
675+
672676
In the case of `xps_listener`:
673677

674678
::: details **expserver/src/network/xps_listener.c**
@@ -697,7 +701,7 @@ void listener_connection_handler(void *ptr) { // [!code ++]
697701
assert(ptr != NULL); // [!code ++]
698702
xps_listener_t *listener = ptr; // [!code ++]
699703

700-
/* same code from xps_listener_connection_handler() */
704+
/* same code logic from xps_listener_connection_handler() */
701705

702706
}
703707
```
@@ -799,7 +803,6 @@ Since we did not modify the functionality of the server, this milestone will is
799803
#include <netdb.h>
800804
#include <netinet/in.h>
801805
#include <stdio.h>
802-
#include <stdlib.h>
803806
#include <string.h>
804807
#include <sys/socket.h>
805808
#include <sys/types.h>
@@ -827,7 +830,7 @@ Since we did not modify the functionality of the server, this milestone will is
827830
return -1;
828831
}
829832
830-
if (connect(sock, (struct sockaddr* )&serv_addr, sizeof(serv_addr)) < 0) {
833+
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
831834
perror("Connection failed");
832835
return -1;
833836
}
@@ -875,7 +878,7 @@ Since we did not modify the functionality of the server, this milestone will is
875878

876879
**What is going on here?**
877880

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.
879882

880883
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.
881884

docs/roadmap/phase-1/stage-8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Make necessary changes in `xps_loop.c`. Here are a few hints:
204204
### Modifications to `xps_connection` Module
205205
206206
- 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.
208208
- 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()` .
209209
- 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` .
210210

docs/roadmap/phase-1/stage-9.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void connection_write_handler(void* ptr) {
116116
}
117117
```
118118
119-
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.
120120
121121
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` .
122122

0 commit comments

Comments
 (0)