Skip to content

Commit

Permalink
Whitespace and cosmetics
Browse files Browse the repository at this point in the history
Fixed excess whitespace, added documentation, switched some types to lw_XX
  • Loading branch information
SortaCore committed Feb 18, 2021
1 parent b79a74e commit 3516717
Show file tree
Hide file tree
Showing 54 changed files with 332 additions and 348 deletions.
2 changes: 1 addition & 1 deletion Lacewing/FrameBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class framebuilder : public messagebuilder
inline void send(lacewing::udp udp, lacewing::address address, bool clear = true)
{
udp->send(address, buffer, size);

if (clear)
framereset();
}
Expand Down
18 changes: 9 additions & 9 deletions Lacewing/FrameReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

class framereader
{

protected:

messagebuilder buffer;

lw_i32 state = 0;
lw_i32 sizebytesleft = 0;
lw_ui32 messagesize = 0;
lw_ui8 messagetype = 0;
lw_ui8 messagetype = 0;

public:

Expand All @@ -61,19 +61,19 @@ class framereader
switch(state)
{
case 0: /* haven't yet got type */

messagetype = byte;
state = 1;
sizebytesleft = 0;

break;

case 1: /* have type, but no size */
{
if (sizebytesleft > 0)
{
buffer.add <char> (byte);

if ((-- sizebytesleft) == 0)
{
switch(buffer.size)
Expand Down Expand Up @@ -138,7 +138,7 @@ class framereader
if (!messagehandler(tag, messagetype, data, messagesize))
return;
state = 0;


return;
}
Expand All @@ -158,7 +158,7 @@ class framereader

state = 0;
process(data + messagesize, size - messagesize);

return;
}
}
Expand All @@ -169,7 +169,7 @@ class framereader
thismessagebytes = size;

buffer.add(data, thismessagebytes);

size -= thismessagebytes;
data += thismessagebytes;

Expand Down
18 changes: 9 additions & 9 deletions Lacewing/IDPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@
/// available ID numbers used first, etc. </summary>
class IDPool
{

protected:

std::set<unsigned short> releasedIDs; // A sorted list of all released IDs.
unsigned short nextID; // The next ID to use, not within releasedIDs.
int borrowedCount; // The number of IDs currently in use.
std::set<lw_ui16> releasedIDs; // A sorted list of all released IDs.
lw_ui16 nextID; // The next ID to use, not within releasedIDs.
lw_i32 borrowedCount; // The number of IDs currently in use.
lacewing::readwritelock lock;

public:

/// <summary> Creates an ID pool. First ID returned is 0. </summary>
IDPool()
{
nextID = 0;
nextID = 0;
borrowedCount = 0;
}

/// <summary> Gets the next ID available from the pool. </summary>
/// <returns> New ID to use. </returns>
unsigned short borrow()
lw_ui16 borrow()
{
lacewing::writelock writeLock = lock.createWriteLock();

Expand All @@ -68,17 +68,17 @@ class IDPool

if (!releasedIDs.empty())
{
unsigned short s = *releasedIDs.cbegin(); // .front() not in std::set
lw_ui16 freshID = *releasedIDs.cbegin(); // .front() not in std::set
releasedIDs.erase(releasedIDs.cbegin());
return s;
return freshID;
}

return nextID ++;
}

/// <summary> Returns the given identifier. </summary>
/// <param name="ID"> The identifier to return. </param>
void returnID(unsigned short ID)
void returnID(lw_ui16 ID)
{
lacewing::writelock writeLock = lock.createWriteLock();
// No IDs in use at all: empty list
Expand Down
84 changes: 47 additions & 37 deletions Lacewing/Lacewing.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ typedef lw_i8 lw_bool;

lw_import lw_stream lw_stream_new (const lw_streamdef *, lw_pump);
lw_import const lw_streamdef * lw_stream_get_def (lw_stream);
lw_import void * lw_stream_tail (lw_stream);
lw_import lw_stream lw_stream_from_tail (void *);
lw_import void lw_stream_data (lw_stream, const char * buffer, size_t size);
lw_import void * lw_stream_tail (lw_stream);
lw_import lw_stream lw_stream_from_tail (void *);
lw_import void lw_stream_data (lw_stream, const char * buffer, size_t size);

/* FDStream */

Expand All @@ -409,7 +409,7 @@ typedef lw_i8 lw_bool;
(lw_file, const char * filename, const char * mode);

lw_import lw_bool lw_file_open_temp (lw_file);
lw_import const char * lw_file_name (lw_file);
lw_import const char * lw_file_name (lw_file);

/* Pipe */

Expand Down Expand Up @@ -466,7 +466,7 @@ typedef lw_i8 lw_bool;
* applicable. To delete a lw_client, use lw_stream_delete.
*/

lw_import lw_client lw_client_new (lw_pump);
lw_import lw_client lw_client_new (lw_pump);
lw_import void lw_client_connect (lw_client, const char * host, long port);
lw_import void lw_client_connect_addr (lw_client, lw_addr);
lw_import void lw_client_connect_secure (lw_client, const char * host, long port);
Expand Down Expand Up @@ -765,14 +765,14 @@ struct _pump
#else

lw_import lw_pump_watch add (int fd, void * tag,
lw_pump_callback on_read_ready,
lw_pump_callback on_write_ready = 0,
bool edge_triggered = true);
lw_pump_callback on_read_ready,
lw_pump_callback on_write_ready = 0,
bool edge_triggered = true);

lw_import void update_callbacks (lw_pump_watch, void * tag,
lw_pump_callback on_read_ready,
lw_pump_callback on_write_ready = 0,
bool edge_triggered = true);
lw_pump_callback on_read_ready,
lw_pump_callback on_write_ready = 0,
bool edge_triggered = true);

#endif

Expand Down Expand Up @@ -924,10 +924,10 @@ struct _stream
lw_import void write_file (const char * filename);

lw_import void add_filter_upstream
(stream, bool delete_with_stream = false, bool close_together = false);
(stream, bool delete_with_stream = false, bool close_together = false);

lw_import void add_filter_downstream
(stream, bool delete_with_stream = false, bool close_together = false);
(stream, bool delete_with_stream = false, bool close_together = false);

lw_import bool close (bool immediate = false);

Expand Down Expand Up @@ -1136,7 +1136,7 @@ struct _server
typedef void (lw_callback * hook_disconnect) (server, server_client);

typedef void (lw_callback * hook_data)
(server, server_client, const char * buffer, size_t size);
(server, server_client, const char * buffer, size_t size);

typedef void (lw_callback * hook_error) (server, error);

Expand Down Expand Up @@ -1234,7 +1234,7 @@ struct _webserver

lw_import bool load_sys_cert
(const char * store_name, const char * common_name,
const char * location = "CurrentUser");
const char * location = "CurrentUser");

lw_import bool cert_loaded ();

Expand Down Expand Up @@ -1263,14 +1263,14 @@ struct _webserver
typedef void (lw_callback * hook_upload_post)
(webserver, webserver_request, webserver_upload uploads[], size_t num_uploads);

lw_import void on_get (hook_get);
lw_import void on_upload_start (hook_upload_start);
lw_import void on_upload_chunk (hook_upload_chunk);
lw_import void on_upload_done (hook_upload_done);
lw_import void on_upload_post (hook_upload_post);
lw_import void on_post (hook_post);
lw_import void on_head (hook_head);
lw_import void on_disconnect (hook_disconnect);
lw_import void on_get (hook_get);
lw_import void on_upload_start (hook_upload_start);
lw_import void on_upload_chunk (hook_upload_chunk);
lw_import void on_upload_done (hook_upload_done);
lw_import void on_upload_post (hook_upload_post);
lw_import void on_post (hook_post);
lw_import void on_head (hook_head);
lw_import void on_disconnect (hook_disconnect);
lw_import void on_error (hook_error);

lw_import void tag (void *);
Expand Down Expand Up @@ -1584,8 +1584,8 @@ struct readlock {
readwritelock & lock;
std::shared_lock<decltype(readwritelock::lock)> locker;
bool locked = true;

};

struct writelock {
friend readwritelock;
friend readlock;
Expand Down Expand Up @@ -1920,12 +1920,12 @@ struct relayserver
std::atomic<bool> _readonly = false;
relayserverinternal &server;

std::vector<std::shared_ptr<relayserver::client>> clients;
std::vector<std::shared_ptr<relayserver::client>> clients;

std::string _name;
lw_ui16 _id = 0xFFFF;
bool _hidden = true;
bool _autoclose = false;
lw_ui16 _id = 0xFFFF;
bool _hidden = true;
bool _autoclose = false;
// TODO: should be weak_ptr?
std::shared_ptr<client> _channelmaster;

Expand Down Expand Up @@ -2013,20 +2013,30 @@ struct relayserver

bool pseudoUDP = true; // Is UDP not supported (e.g. Flash) so "faked" by receiver

bool connectRequestApproved = false;
bool gotfirstbyte = false;
bool pongedOnTCP = true;
// Got opening null byte, indicating not a HTTP client.
bool gotfirstbyte = false;
// After TCP connect approval, Lacewing connect message request was received, and server has said OK to it
bool connectRequestApproved = false;
// Client has only ever used valid Lacewing messages; e.g. valid UTF-8, no missing elements in messages.
// Does not indicate all messages succeed. When false, client is kicked very shortly after.
bool trustedClient = true;
// Has a TCP ping request been sent by server, and was replied to.
// If false, next ping timer tick will consider a failed ping and kick the client, so it is true by default.
bool pongedOnTCP = true;

lacewing::address udpaddress;
void PeerToPeer(relayserver &server, std::shared_ptr<relayserver::channel> viachannel, std::shared_ptr<relayserver::client> receivingclient,
bool blasted, lw_ui8 subchannel, lw_ui8 variant, std::string_view message);
lacewing::address udpaddress;

lw_ui16 _id = 0xFFFF;

bool checkname(std::string_view name);
void PeerToPeer(relayserver &server, std::shared_ptr<relayserver::channel> viachannel, std::shared_ptr<relayserver::client> receivingclient,
bool blasted, lw_ui8 subchannel, lw_ui8 variant, std::string_view message);

lw_ui16 _id = 0xFFFF;
// Checks if name can be set to given name, by this client.
// Checks whether name is valid, and whether name is in use already.
bool checkname(std::string_view name);

std::shared_ptr<relayserver::channel> readchannel(messagereader &reader);
// Reads channel from client's channel list; fails if not joined.
std::shared_ptr<relayserver::channel> readchannel(messagereader &reader);
};

size_t clientcount() const;
Expand Down
28 changes: 1 addition & 27 deletions Lacewing/MessageReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class messagereader
protected:

const char * buffer;

size_t size;

std::vector<char *> tofree;
Expand Down Expand Up @@ -134,32 +134,6 @@ class messagereader
offset += size;
}

/* inline short Network16Bit ()
{
return ntohs (Get <short> ());
}
inline int Network24Bit ()
{
if (!Check (3))
return 0;
return Read24Bit (Buffer + Offset);
}
inline int Network32Bit ()
{
return ntohl (Get <int> ());
}
inline int NetworkX31Bit ()
{
int value = Get <int> ();
*(char *) &value &= 0x7F;
return ntohl (value);
}*/
};

#endif
Expand Down
Loading

0 comments on commit 3516717

Please sign in to comment.