mirror of
https://github.com/Wessel/c-websocket-server.git
synced 2026-07-22 00:07:29 +02:00
feat: Populate repo
This commit is contained in:
38
git/wsserver/doc/man/man3/ws_close_client.3
Normal file
38
git/wsserver/doc/man/man3/ws_close_client.3
Normal file
@@ -0,0 +1,38 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_close_connection \- Close the client connection.
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "int ws_close_client(ws_cli_conn_t " *client ");
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_close_client ()
|
||||
for a given client
|
||||
.I client
|
||||
, closes the client connection with normal close code (1000) and no
|
||||
reason string.
|
||||
.SH RETURN VALUE
|
||||
Returns 0 if success, -1 otherwise.
|
||||
.SH NOTES
|
||||
If the client did not send a close frame in TIMEOUT_MS ms (500 ms), the
|
||||
server will close the connection with error code (1002).
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
46
git/wsserver/doc/man/man3/ws_get_state.3
Normal file
46
git/wsserver/doc/man/man3/ws_get_state.3
Normal file
@@ -0,0 +1,46 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_get_state \- Get a client current state
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "int ws_get_state(ws_cli_conn_t " *client ");
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_get_state ()
|
||||
for a given client
|
||||
.I client
|
||||
, gets the current state. Valid states are:
|
||||
.PP
|
||||
.RS 2
|
||||
.IP \(em 2
|
||||
WS_STATE_CONNECTING (0)
|
||||
.IP \(em 2
|
||||
WS_STATE_OPEN (1)
|
||||
.IP \(em 2
|
||||
WS_STATE_CLOSING (2)
|
||||
.IP \(em 2
|
||||
WS_STATE_CLOSED (3)
|
||||
.PP
|
||||
Anything other than that should be considered an error.
|
||||
.SH RETURN VALUE
|
||||
Returns the client state or -1 if error.
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
37
git/wsserver/doc/man/man3/ws_getaddress.3
Normal file
37
git/wsserver/doc/man/man3/ws_getaddress.3
Normal file
@@ -0,0 +1,37 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_getaddress \- Gets the client IP address
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "char* ws_getaddress(ws_cli_conn_t " "*client" );
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_getaddress ()
|
||||
obtains the client IP address as a string for a given
|
||||
.I client
|
||||
passed as parameter.
|
||||
.SH NOTES
|
||||
.PP
|
||||
The returned string is static, no need to free up memory.
|
||||
.SH RETURN VALUE
|
||||
Returns a string containing the client IP address or null if error.
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
44
git/wsserver/doc/man/man3/ws_ping.3
Normal file
44
git/wsserver/doc/man/man3/ws_ping.3
Normal file
@@ -0,0 +1,44 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "29 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_ping \- Sends a ping to a single client or broadcast
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "void ws_ping(ws_cli_conn_t " *client ", int " broadcast ");"
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_ping ()
|
||||
sends a ping message to the
|
||||
.I client
|
||||
(or broadcast if NULL) with a given
|
||||
.I threshold.
|
||||
Although wsServer supports sending PINGs, they are not automatic: the user
|
||||
needs to invoke
|
||||
.BR ws_ping()
|
||||
periodically, whether in a separate thread (recommended) or not.
|
||||
|
||||
The interval between each call determines the 'timeout' between PINGs.
|
||||
|
||||
Threshold must be positive and greater than zero, and determines how many
|
||||
PINGs can be ignored.
|
||||
.SH RETURN VALUE
|
||||
The function does not return any value.
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
66
git/wsserver/doc/man/man3/ws_sendframe.3
Normal file
66
git/wsserver/doc/man/man3/ws_sendframe.3
Normal file
@@ -0,0 +1,66 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_sendframe \- Creates and send a masked WebSocket frame with some payload data.
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "int ws_sendframe(ws_cli_conn_t " *client ", const char " *msg ", ssize_t " size ", int " type ");
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_sendframe ()
|
||||
sends a given message
|
||||
.I msg
|
||||
to the client
|
||||
.I client
|
||||
with the size
|
||||
.I size
|
||||
for a given frame
|
||||
.I type.
|
||||
This routine is intended to be used to create a websocket frame for
|
||||
a given type and sending to the client. For higher level routines,
|
||||
please check
|
||||
.I ws_sendframe_txt
|
||||
and
|
||||
.I ws_sendframe_bin.
|
||||
.SH RETURN VALUE
|
||||
Returns the number of bytes written.
|
||||
.SH NOTES
|
||||
.PP
|
||||
The parameter
|
||||
.I size
|
||||
can be any value or -1, if the later, the size will be automatically calculated
|
||||
from the message. Please note that null terminated strings are expected.
|
||||
.PP
|
||||
The acceptable values for
|
||||
.I type
|
||||
are:
|
||||
.BR WS_FR_OP_TXT,
|
||||
.BR WS_FR_OP_BIN
|
||||
and
|
||||
.BR WS_FR_OP_PONG.
|
||||
.PP
|
||||
If the parameter
|
||||
.I client
|
||||
is NULL, a broadcast message will be sent instead.
|
||||
.SH SEE ALSO
|
||||
.BR ws_sendframe_txt (3),
|
||||
.BR ws_sendframe_bin (3)
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
45
git/wsserver/doc/man/man3/ws_sendframe_bin.3
Normal file
45
git/wsserver/doc/man/man3/ws_sendframe_bin.3
Normal file
@@ -0,0 +1,45 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_sendframe_bin \- Sends a WebSocket binary frame.
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "int ws_sendframe_bin(ws_cli_conn_t " *client ", const char " *msg ", size " size ");
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_sendframe_bin ()
|
||||
sends a given text message
|
||||
.I msg
|
||||
to the client
|
||||
.I client
|
||||
with size
|
||||
.I size
|
||||
.SH NOTES
|
||||
.PP
|
||||
If the parameter
|
||||
.I client
|
||||
is NULL, a broadcast message will be sent instead.
|
||||
.SH RETURN VALUE
|
||||
Returns the number of bytes written.
|
||||
.SH SEE ALSO
|
||||
.BR ws_sendframe (3),
|
||||
.BR ws_sendframe_txt (3)
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
43
git/wsserver/doc/man/man3/ws_sendframe_txt.3
Normal file
43
git/wsserver/doc/man/man3/ws_sendframe_txt.3
Normal file
@@ -0,0 +1,43 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_sendframe_txt \- Sends a WebSocket text frame.
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "int ws_sendframe_txt(ws_cli_conn_t " *client ", const char " *msg ");
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_sendframe_txt ()
|
||||
sends a given text message
|
||||
.I msg
|
||||
to the client
|
||||
.I client
|
||||
.SH NOTES
|
||||
.PP
|
||||
If the parameter
|
||||
.I client
|
||||
is NULL, a broadcast message will be sent instead.
|
||||
.SH RETURN VALUE
|
||||
Returns the number of bytes written.
|
||||
.SH SEE ALSO
|
||||
.BR ws_sendframe (3),
|
||||
.BR ws_sendframe_bin (3)
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
90
git/wsserver/doc/man/man3/ws_socket.3
Normal file
90
git/wsserver/doc/man/man3/ws_socket.3
Normal file
@@ -0,0 +1,90 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2016-2022 Davidson Francis <davidsondfgl@gmail.com>
|
||||
.\"
|
||||
.\" This program is free software: you can redistribute it and/or modify
|
||||
.\" it under the terms of the GNU General Public License as published by
|
||||
.\" the Free Software Foundation, either version 3 of the License, or
|
||||
.\" (at your option) any later version.
|
||||
.\"
|
||||
.\" This program is distributed in the hope that it will be useful,
|
||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
.\" GNU General Public License for more details.
|
||||
.\"
|
||||
.\" You should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.\"
|
||||
.TH man 3 "04 Apr 2022" "1.0" "wsServer man page"
|
||||
.SH NAME
|
||||
ws_socket \- Start the WebSocket server
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B #include <ws.h>
|
||||
.sp
|
||||
.BI "int ws_socket(struct ws_events " *evs ", uint16_t " port ", int " tloop ", "
|
||||
.BI uint32_t " timeout_ms " );
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR ws_socket ()
|
||||
starts the websocket server for the configured events
|
||||
.IR evs ,
|
||||
port number
|
||||
.IR port .
|
||||
and
|
||||
.IR tloop .
|
||||
The parameter
|
||||
.I tloop
|
||||
specifies if the accept loop should run on the same thread (if equals 0)
|
||||
or on a different thread (if != 0).
|
||||
|
||||
Optionally, a user can set a pre-defined
|
||||
.I timeout_ms
|
||||
time (in milliseconds) that each message should have. Think of it like a 'ping':
|
||||
if the client doesn't respond in x amount of time, the client is unresponsive
|
||||
and the server shouldn't bother sending message to it.
|
||||
|
||||
In case of doubt, leave as 0.
|
||||
.SH RETURN VALUE
|
||||
If
|
||||
.I tloop
|
||||
is equals 0, this function blocks and never returns. Otherwise, returns 0.
|
||||
.SH NOTES
|
||||
.PP
|
||||
The structure
|
||||
.I evs
|
||||
is defined as follows:
|
||||
.nf
|
||||
struct ws_events
|
||||
{
|
||||
void (*onopen)(ws_cli_conn_t *client);
|
||||
void (*onclose)(ws_cli_conn_t *client);
|
||||
void (*onmessage)(ws_cli_conn_t *client,
|
||||
const unsigned char * msg,
|
||||
uint64_t size, int type);
|
||||
};
|
||||
.fi
|
||||
|
||||
Each element corresponds to function pointers that are triggered when the
|
||||
events occur.
|
||||
|
||||
The events:
|
||||
.RS 2
|
||||
.IP \(em 2
|
||||
on_open: occurs when a client successfully connects and handshakes with the
|
||||
server.
|
||||
.IP \(em 2
|
||||
on_close: occurs when a valid client (that handshaked with the server)
|
||||
disconnects with the server. The reason is not informed.
|
||||
.IP \(em 2
|
||||
on_message: occurs when a client sends a message (whether txt or bin) to the
|
||||
server.
|
||||
.PP
|
||||
Also note that the thread that sends the events is the same as that deals
|
||||
with the client connection, so keep in mind that you need to let the
|
||||
function return. If you want to perform further processing, consider
|
||||
creating a new thread.
|
||||
.SH SEE ALSO
|
||||
.BR ws_sendframe_txt (3),
|
||||
.BR ws_sendframe_bin (3)
|
||||
.SH AUTHOR
|
||||
Davidson Francis (davidsondfgl@gmail.com)
|
||||
Reference in New Issue
Block a user