Skip to content

Commit fc49c8f

Browse files
authored
Update README.md
1 parent 88d2a00 commit fc49c8f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Table of Contents
1111
* [Usage](#usage)
1212
* [Frame builder](#frame-builder)
1313
* [UUID](#uuid)
14-
* [Test frame](#test-frame)
14+
* [Frame example](#frame-example)
1515

1616
Features
1717
--------
@@ -53,20 +53,20 @@ These functions must match the signatures defined in the websocket-parser header
5353
5454
Returning a value other than 0 from the callbacks will abort message processing.
5555
56-
One websocket_parser object is used per TCP connection. Initialize `websocket_parser` struct using `websocket_parser_init()` and set the callbacks.
57-
That might look something like this for a frame parser:
56+
One websocket_parser object is used per TCP connection. Initialize `websocket_parser` struct using `websocket_parser_init()` and set callbacks:
5857
5958
```c
6059
websocket_parser_settings settings;
6160
6261
websocket_parser_settings_init(&settings);
6362
6463
settings.on_frame_header = websocket_frame_header;
65-
settings.on_frame_body = websocket_frame_body;
66-
settings.on_frame_end = websocket_frame_end;
64+
settings.on_frame_body = websocket_frame_body;
65+
settings.on_frame_end = websocket_frame_end;
6766
6867
parser = malloc(sizeof(websocket_parser));
6968
websocket_parser_init(parser);
69+
// Attention! Sets your 'data' after websocket_parser_init
7070
parser->data = my_frame_struct; // set your custom data after websocket_parser_init() function
7171
```
7272

@@ -77,7 +77,7 @@ int websocket_frame_header(websocket_parser * parser) {
7777
parser->data->opcode = parser->flags & WS_OP_MASK; // gets opcode
7878
parser->data->is_final = parser->flags & WS_FIN; // checks is final frame
7979
if(parser->length) {
80-
parser->data->body = malloc(parser->length); // allocate memory for frame body, if body exists
80+
parser->data->body = malloc(parser->length); // allocate memory for frame body, if body exists
8181
}
8282
return 0;
8383
}
@@ -115,20 +115,20 @@ free(parser);
115115
Frame builder
116116
-------------
117117

118-
Calculate required memory for frame using `websocket_calc_frame_size` function
118+
To calculate how many bytes to allocate for a frame, use the `websocket_calc_frame_size` function:
119119

120120
```c
121121
size_t frame_len = websocket_calc_frame_size(WS_OP_TEXT | WS_FINAL_FRAME | WS_HAS_MASK, data_len);
122122
char * frame = malloc(sizeof(char) * frame_len);
123123
```
124124

125-
build frame
125+
After that you can build a frame
126126

127127
```c
128128
websocket_build_frame(frame, WS_OP_TEXT | WS_FINAL_FRAME | WS_HAS_MASK, mask, data, data_len);
129129
```
130130
131-
and send binary string
131+
and send binary string to the socket
132132
133133
```c
134134
write(sock, frame, frame_len);
@@ -137,14 +137,14 @@ write(sock, frame, frame_len);
137137
UUID
138138
----
139139

140-
Macro WEBSOCKET_UUID contains unique ID for handshake
140+
Macros WEBSOCKET_UUID contains unique ID for handshake
141141

142142
```c
143143
#define WEBSOCKET_UUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
144144
```
145145
146-
Test frame
147-
----------
146+
Frame example
147+
-------------
148148
149149
There is websocket frame example:
150150

0 commit comments

Comments
 (0)