Skip to content

Commit ac73b91

Browse files
authored
Merge pull request #9 from FayisRahman/master
fixed some docs in stage 11 and stage 13
2 parents 6a9bebd + 6303e07 commit ac73b91

10 files changed

Lines changed: 221 additions & 226 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ Now that `buff` has the reversed string, it is time to send it to the client. We
297297
298298
---
299299
300-
The final code should look like this.
300+
The final code should look like this. {#tcp-server-c}
301+
301302
302-
<a id="tcp-server-c"></a>
303303
::: details expserver/phase_0/tcp_server.c
304304
305305

docs/roadmap/phase-0/stage-4.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ event flags indicating which I/O conditions to monitor (`EPOLLIN`, `EPOLLOUT`, e
121121

122122
<!--since nested block is not possible this is a workaround using HTML code-->
123123
<div class="custom-block danger">
124-
<p class="custom-block-title">NOTE</p>
125124
<p>
126125
In this project, the results of <code>epoll_wait()</code> are kept in an array
127126
named <code>events</code>, so the event flags naturally appear in the code as

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ The below is the code for the header file `xps_upstream.h`. Have a look at it an
3838
::: details **expserver/src/network/xps_upstream.h**
3939

4040
```c
41-
#ifndef XPS_UPSTREAM_H
42-
#define XPS_UPSTREAM_H
43-
44-
#include "../xps.h"
45-
46-
xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int port);
47-
48-
#endif
41+
#ifndef XPS_UPSTREAM_H
42+
#define XPS_UPSTREAM_H
43+
44+
#include "../xps.h"
45+
46+
xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int port);
47+
48+
#endif
4949
```
5050
:::
5151

@@ -57,9 +57,7 @@ The below is the code for the header file `xps_upstream.h`. Have a look at it an
5757
xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int port) {
5858
/* validate parameter */
5959

60-
/* create a socket and connect to host and port to upstream using xps_getaddrinfo and connect function */
61-
62-
60+
/* create a socket and connect to host and port to upstream using xps_getaddrinfo and connect function */
6361

6462
if (!(connect_error == 0 || errno == EINPROGRESS)) {
6563
logger(LOG_ERROR, "xps_upstream_create()", "connect() failed");
@@ -74,6 +72,9 @@ xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int
7472
return connection;
7573
}
7674
```
75+
:::warning
76+
Dont forget to free allocated struct addrinfo
77+
:::
7778
7879
## Modifications to listener module
7980
@@ -105,7 +106,7 @@ void listener_connection_handler(void *ptr) {
105106
106107
/* create upstream connection */
107108
/*create pipe connection to client source and upstream sink for the listener*/
108-
/*create pipe a connection to upstream source and client sink for the listener*/
109+
/*create pipe connection to upstream source and client sink for the listener*/
109110
} else {
110111
/* same as previous stages*/
111112

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Create a new folder disk in src, this would be used for adding necessary modules
3434

3535
The code below has the contents of the header file for `xps_mime`. Have a look at it and make a copy of it in your codebase.
3636

37-
:::details **expserver/src/disc/xps_mime.h**
37+
:::details **expserver/src/disk/xps_mime.h**
3838

3939
```c
4040
#ifndef XPS_MIME_H
@@ -52,7 +52,7 @@ const char *xps_get_mime(const char *file_path);
5252

5353
The function `xps_get_mime()` returns the MIME type of a file based on its extension. A MIME type lookup table (`mime_types`) maps file extensions (e.g., ".html", ".jpg") to their corresponding MIME types (e.g., "text/html", "image/jpeg"). This tells the browser how to display or interact with the file. For example, an HTML file is rendered as a web page, while an image is displayed as a picture. We won’t be using this functionality in the present stage but would be looking into in later stages.
5454

55-
:::details **expserver/src/disc/xps_mime.c**
55+
:::details **expserver/src/disk/xps_mime.c**
5656

5757
```c
5858
#include "../xps.h"
@@ -88,7 +88,7 @@ const char *xps_get_mime(const char *file_path) {
8888
```
8989
:::
9090

91-
As we are mapping the MIME type based on the file extension, a function for finding the file extension is added in `xps_utility`. Add the below given function in utility.c
91+
As we are mapping the MIME type based on the file extension, a function for finding the file extension is added in `xps_utils.h`. Add the below given function in `xps_utils.c`
9292

9393
```c
9494
const char *get_file_ext(const char *file_path) {
@@ -108,7 +108,7 @@ Also declare the newly created function in utility.h
108108
109109
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.
110110
111-
:::details **expserver/src/disc/xps_file.h**
111+
:::details **expserver/src/disk/xps_file.h**
112112
113113
```c
114114
#ifndef XPS_FILE_H
@@ -157,7 +157,7 @@ Several file system-related C standard library functions are used to handle file
157157
FILE *fopen(const char *filename, const char *mode);
158158
```
159159

160-
Opens a file specified by filename and returns a pointer to a FILE structure that represents the file stream. If mode given as “rb”, it opens the file in binary read mode. **Returns**: A pointer to a FILE structure if successful, or NULL if the file cannot be opened .
160+
Opens a file specified by filename and returns a pointer to a FILE structure that represents the file stream. If mode given as “rb”, it opens the file in binary read mode. **Returns**: A pointer to a FILE structure if successful, or NULL if the file cannot be opened.
161161

162162
- `fclose()`
163163

@@ -241,7 +241,7 @@ The functions in xps_file.c are given below:
241241
FILE *file_struct = fopen(file_path, "rb");
242242
/*handle EACCES,ENOENT or any other error*/
243243
if (file_struct == NULL) {
244-
/*logs EACCES,ENOENT or any other error*/
244+
/*logs EACCES,ENOENT or any other error*/
245245
return NULL;
246246
}
247247

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ xps_session_t *xps_session_create(xps_core_t *core, xps_connection_t *client) {
117117
// Alloc memory for session instance
118118
xps_session_t *session = /* fill this */
119119
if (session == NULL) {
120-
logger(LOG_ERROR, "xps_session_create()", "malloc() failed fro 'session'");
120+
logger(LOG_ERROR, "xps_session_create()", "malloc() failed for 'session'");
121121
return NULL;
122122
}
123123

@@ -190,14 +190,28 @@ xps_session_t *xps_session_create(xps_core_t *core, xps_connection_t *client) {
190190

191191
if (client->listener->port == 8001) {
192192
xps_connection_t *upstream = /* fill this */
193-
xps_pipe_create(/* fill this */)
194-
xps_pipe_create(/* fill this */)
193+
if (upstream == NULL) {
194+
logger(LOG_ERROR, "xps_session_create()", "xps_upstream_create() failed");
195+
perror("Error message");
196+
/* destroy session */
197+
return NULL;
198+
}
199+
session->upstream = /* fill this */;
200+
xps_pipe_create(/* fill this */);
201+
xps_pipe_create(/* fill this */);
195202
}
196203

197204
else if (client->listener->port == 8002) {
198205
int error;
199-
xps_file_t *file = xps_file_create(/* fill this */)
200-
xps_pipe_create(/* fill this */)
206+
xps_file_t *file = xps_file_create(/* fill this */);
207+
if (file == NULL) {
208+
logger(LOG_ERROR, "xps_session_create()", "xps_file_create() failed");
209+
perror("Error message");
210+
/*destory session*/
211+
return NULL;
212+
}
213+
/* assign to the file member */
214+
xps_pipe_create(/* fill this */);
201215
}
202216

203217
return session;
@@ -491,12 +505,12 @@ void listener_connection_handler(void *ptr) {
491505
continue;
492506
}
493507
client->listener = listener;
494-
495-
// TEMP
508+
496509
xps_session_t *session = /* fill this */ ;
497510
if (session == NULL) {
498511
logger(LOG_ERROR, "listener_connection_handler()", "xps_session_create() failed");
499512
xps_connection_destroy(client);
513+
return;
500514
}
501515
502516
logger(LOG_INFO, "listener_connection_handler()", "new connection");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ In Stage 5, we had three types of events that could occur in epoll:
638638
Since this stage involves receiving a message from the client, reversing it and sending it back, we won’t not be needing upstream. We will work on the first two types of events:
639639
640640
::: tip NOTE
641-
Upstream will have its own module (`xps_upstream`) and will be implemented in Stage 9.
641+
Upstream will have its own module (`xps_upstream`) and will be implemented in Stage 11.
642642
:::
643643
644644
- **Read event on listening socket:**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ Since we did not modify the functionality of the server, this milestone will is
827827
return -1;
828828
}
829829
830-
if (connect(sock, (struct sockaddr \*)&serv_addr, sizeof(serv_addr)) < 0) {
830+
if (connect(sock, (struct sockaddr* )&serv_addr, sizeof(serv_addr)) < 0) {
831831
perror("Connection failed");
832832
return -1;
833833
}

0 commit comments

Comments
 (0)