Invoke ALEFix

This commit is contained in:
Stephen Seo 2019-06-06 16:42:07 +09:00
parent 2aa4600c57
commit 28d832a349
3 changed files with 69 additions and 86 deletions

View file

@ -3,9 +3,9 @@
#define UDPC_CONTEXT_IDENTIFIER 0x902F4DB3 #define UDPC_CONTEXT_IDENTIFIER 0x902F4DB3
#include <cstdint>
#include <bitset>
#include <atomic> #include <atomic>
#include <bitset>
#include <cstdint>
#include "UDPConnection.h" #include "UDPConnection.h"

View file

@ -1,11 +1,9 @@
#include "UDPConnection.h"
#include "UDPC_Defines.hpp" #include "UDPC_Defines.hpp"
#include "UDPConnection.h"
UDPC::Context::Context(bool isThreaded) : UDPC::Context::Context(bool isThreaded)
_contextIdentifier(UDPC_CONTEXT_IDENTIFIER), : _contextIdentifier(UDPC_CONTEXT_IDENTIFIER), flags(),
flags(), isAcceptNewConnections(true), protocolID(UDPC_DEFAULT_PROTOCOL_ID),
isAcceptNewConnections(true),
protocolID(UDPC_DEFAULT_PROTOCOL_ID),
#ifndef NDEBUG #ifndef NDEBUG
loggingType(INFO) loggingType(INFO)
#else #else
@ -37,7 +35,8 @@ void* UDPC_init(uint16_t listenPort, uint32_t listenAddr, int isClient) {
return ctx; return ctx;
} }
void* UDPC_init_threaded_update(uint16_t listenPort, uint32_t listenAddr, int isClient) { void *UDPC_init_threaded_update(uint16_t listenPort, uint32_t listenAddr,
int isClient) {
UDPC::Context *ctx = new UDPC::Context(true); UDPC::Context *ctx = new UDPC::Context(true);
return ctx; return ctx;
@ -71,7 +70,8 @@ int UDPC_get_queue_send_available(void *ctx, uint32_t addr) {
return 0; return 0;
} }
void UDPC_queue_send(void *ctx, uint32_t destAddr, uint16_t destPort, uint32_t isChecked, void *data, uint32_t size) { void UDPC_queue_send(void *ctx, uint32_t destAddr, uint16_t destPort,
uint32_t isChecked, void *data, uint32_t size) {
if (!UDPC::VerifyContext(ctx)) { if (!UDPC::VerifyContext(ctx)) {
return; return;
} }
@ -127,22 +127,18 @@ const char* UDPC_atostr(void *ctx, uint32_t addr) {
} }
UDPC::Context *c = (UDPC::Context *)ctx; UDPC::Context *c = (UDPC::Context *)ctx;
int index = 0; int index = 0;
for(int x = 0; x < 4; ++x) for (int x = 0; x < 4; ++x) {
{
unsigned char temp = (addr >> (x * 8)) & 0xFF; unsigned char temp = (addr >> (x * 8)) & 0xFF;
if(temp >= 100) if (temp >= 100) {
{
c->atostrBuf[index++] = '0' + temp / 100; c->atostrBuf[index++] = '0' + temp / 100;
} }
if(temp >= 10) if (temp >= 10) {
{
c->atostrBuf[index++] = '0' + ((temp / 10) % 10); c->atostrBuf[index++] = '0' + ((temp / 10) % 10);
} }
c->atostrBuf[index++] = '0' + temp % 10; c->atostrBuf[index++] = '0' + temp % 10;
if(x < 3) if (x < 3) {
{
c->atostrBuf[index++] = '.'; c->atostrBuf[index++] = '.';
} }
} }
@ -155,32 +151,23 @@ uint32_t UDPC_strtoa(const char *addrStr) {
uint32_t addr = 0; uint32_t addr = 0;
uint32_t temp = 0; uint32_t temp = 0;
uint32_t index = 0; uint32_t index = 0;
while(*addrStr != 0) while (*addrStr != 0) {
{ if (*addrStr >= '0' && *addrStr <= '9') {
if(*addrStr >= '0' && *addrStr <= '9')
{
temp *= 10; temp *= 10;
temp += *addrStr - '0'; temp += *addrStr - '0';
} } else if (*addrStr == '.' && temp <= 0xFF && index < 3) {
else if(*addrStr == '.' && temp <= 0xFF && index < 3)
{
addr |= (temp << (8 * index++)); addr |= (temp << (8 * index++));
temp = 0; temp = 0;
} } else {
else
{
return 0; return 0;
} }
++addrStr; ++addrStr;
} }
if(index == 3 && temp <= 0xFF) if (index == 3 && temp <= 0xFF) {
{
addr |= temp << 24; addr |= temp << 24;
return addr; return addr;
} } else {
else
{
return 0; return 0;
} }
} }

View file

@ -23,9 +23,9 @@
#define CleanupSocket(x) closesocket(x) #define CleanupSocket(x) closesocket(x)
#elif UDPC_PLATFORM == UDPC_PLATFORM_MAC || UDPC_PLATFORM == UDPC_PLATFORM_LINUX #elif UDPC_PLATFORM == UDPC_PLATFORM_MAC || UDPC_PLATFORM == UDPC_PLATFORM_LINUX
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h> #include <fcntl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#define CleanupSocket(x) close(x) #define CleanupSocket(x) close(x)
@ -44,13 +44,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#endif #endif
typedef enum { typedef enum { SILENT, ERROR, WARNING, VERBOSE, INFO } UDPC_LoggingType;
SILENT,
ERROR,
WARNING,
VERBOSE,
INFO
} UDPC_LoggingType;
typedef struct { typedef struct {
char data[UDPC_PACKET_MAX_SIZE]; char data[UDPC_PACKET_MAX_SIZE];
@ -62,7 +56,8 @@ typedef struct {
} PacketInfo; } PacketInfo;
void *UDPC_init(uint16_t listenPort, uint32_t listenAddr, int isClient); void *UDPC_init(uint16_t listenPort, uint32_t listenAddr, int isClient);
void* UDPC_init_threaded_update(uint16_t listenPort, uint32_t listenAddr, int isClient); void *UDPC_init_threaded_update(uint16_t listenPort, uint32_t listenAddr,
int isClient);
void UDPC_destroy(void *ctx); void UDPC_destroy(void *ctx);
@ -70,7 +65,8 @@ void UDPC_update(void *ctx);
int UDPC_get_queue_send_available(void *ctx, uint32_t addr); int UDPC_get_queue_send_available(void *ctx, uint32_t addr);
void UDPC_queue_send(void *ctx, uint32_t destAddr, uint16_t destPort, uint32_t isChecked, void *data, uint32_t size); void UDPC_queue_send(void *ctx, uint32_t destAddr, uint16_t destPort,
uint32_t isChecked, void *data, uint32_t size);
int UDPC_set_accept_new_connections(void *ctx, int isAccepting); int UDPC_set_accept_new_connections(void *ctx, int isAccepting);