1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-22 06:40:06 +00:00

lsocket.[ch]: refactored writeInt && readInt

- switched to laikaS_readu* && laikaS_writeu*
- this gets rid of the ugly malloc() for platforms that don't support VLAs
This commit is contained in:
2022-09-07 16:46:18 -05:00
parent dc91a207b1
commit 6ab280d010
12 changed files with 95 additions and 79 deletions

View File

@@ -58,4 +58,28 @@
void *laikaM_realloc(void *buf, size_t sz);
inline bool laikaM_isBigEndian(void)
{
union
{
uint32_t i;
uint8_t c[4];
} _indxint = {0xDEADB33F};
return _indxint.c[0] == 0xDE;
}
inline void laikaM_reverse(uint8_t *buf, size_t sz)
{
int k;
/* swap bytes, reversing the buffer */
for (k = 0; k < (sz / 2); k++) {
uint8_t tmp = buf[k];
buf[k] = buf[sz - k - 1];
buf[sz - k - 1] = tmp;
}
}
#endif

View File

@@ -88,8 +88,6 @@ struct sLaika_socket
#define laikaS_isAlive(arg) (arg->sock != INVALID_SOCKET)
bool laikaS_isBigEndian(void);
void laikaS_init(void);
void laikaS_cleanUp(void);
@@ -114,10 +112,10 @@ void laikaS_readKeyDecrypt(struct sLaika_socket *sock, void *buf, size_t sz, uin
uint8_t *priv); /* decrypts & reads to buf using pub & priv key*/
void laikaS_writeByte(struct sLaika_socket *sock, uint8_t data);
uint8_t laikaS_readByte(struct sLaika_socket *sock);
void laikaS_readInt(struct sLaika_socket *sock, void *buf,
size_t sz); /* reads INT, respecting endianness */
void laikaS_writeInt(struct sLaika_socket *sock, void *buf,
size_t sz); /* writes INT, respecting endianness */
void laikaS_writeu16(struct sLaika_socket *sock, uint16_t i); /* writes UINT16, respecting endianness */
uint16_t laikaS_readu16(struct sLaika_socket *sock); /* reads UINT16, respecting endianness */
void laikaS_writeu32(struct sLaika_socket *sock, uint32_t i); /* writes UINT32, respecting endianness */
uint32_t laikaS_readu32(struct sLaika_socket *sock); /* reads UINT32, respecting endianness */
RAWSOCKCODE laikaS_rawRecv(struct sLaika_socket *sock, size_t sz, int *processed);
RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed);