Merge pull request #57 from CreeperMario/udp-log-fixes

More Miscellaneous Fixes and Features
This commit is contained in:
James 2017-10-10 13:54:53 +01:00 committed by GitHub
commit 1ce68f6d58
22 changed files with 401 additions and 69 deletions

14
.gitmodules vendored
View File

@ -1,9 +1,9 @@
[submodule "tools/ext/zlib"] [submodule "externals/excmd"]
path = externals/zlib
url = https://github.com/madler/zlib.git
[submodule "tools/ext/cppformat"]
path = externals/cppformat
url = https://github.com/cppformat/cppformat.git
[submodule "tools/ext/excmd"]
path = externals/excmd path = externals/excmd
url = https://github.com/exjam/excmd url = https://github.com/exjam/excmd
[submodule "externals/fmt"]
path = externals/fmt
url = https://github.com/fmtlib/fmt
[submodule "externals/zlib"]
path = externals/zlib
url = https://github.com/madler/zlib.git

View File

@ -13,6 +13,8 @@ matrix:
- zlib1g-dev - zlib1g-dev
env: env:
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6" - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
- os: osx
osx_image: xcode8.3
cache: cache:
directories: directories:
@ -25,7 +27,8 @@ git:
submodules: true submodules: true
before_script: before_script:
- wget https://freefr.dl.sourceforge.net/project/devkitpro/devkitPPC/devkitPPC_r29-1/devkitPPC_r29-1-x86_64-linux.tar.bz2 -O /tmp/devkitPPC.tar.bz2 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://freefr.dl.sourceforge.net/project/devkitpro/devkitPPC/devkitPPC_r29-1/devkitPPC_r29-1-x86_64-linux.tar.bz2 -O /tmp/devkitPPC.tar.bz2; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then wget https://freefr.dl.sourceforge.net/project/devkitpro/devkitPPC/devkitPPC_r29-1/devkitPPC_r29-1-x86_64-osx.tar.bz2 -O /tmp/devkitPPC.tar.bz2; fi
- tar -xjf /tmp/devkitPPC.tar.bz2 - tar -xjf /tmp/devkitPPC.tar.bz2
- export DEVKITPPC=$PWD/devkitPPC - export DEVKITPPC=$PWD/devkitPPC

View File

@ -1,10 +1,10 @@
project(libraries) project(libraries)
include(ExternalProject) include(ExternalProject)
# cppformat # fmtlib
set(CPPFORMAT_DIR "cppformat") set(FMTLIB_DIR "fmt")
externalproject_add(cppformat externalproject_add(fmtlib
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${CPPFORMAT_DIR}" SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${FMTLIB_DIR}"
CMAKE_CACHE_ARGS CMAKE_CACHE_ARGS
-DCMAKE_C_COMPILER:string=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER:string=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS:string=${CMAKE_C_FLAGS} -DCMAKE_C_FLAGS:string=${CMAKE_C_FLAGS}
@ -14,28 +14,28 @@ externalproject_add(cppformat
-DFMT_INSTALL:string=off -DFMT_INSTALL:string=off
-DFMT_TEST:string=off -DFMT_TEST:string=off
INSTALL_COMMAND "") INSTALL_COMMAND "")
externalproject_get_property(cppformat BINARY_DIR) externalproject_get_property(fmtlib BINARY_DIR)
set_target_properties(cppformat PROPERTIES FOLDER libraries) set_target_properties(fmtlib PROPERTIES FOLDER libraries)
if(MSVC) if(MSVC)
set(CPPFORMAT_IMPORTED_LOCATION set(FMTLIB_IMPORTED_LOCATION
IMPORTED_LOCATION_DEBUG "${BINARY_DIR}/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}cppformat${CMAKE_FIND_LIBRARY_SUFFIXES}" IMPORTED_LOCATION_DEBUG "${BINARY_DIR}/fmt/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}fmt${CMAKE_FIND_LIBRARY_SUFFIXES}"
IMPORTED_LOCATION_RELEASE "${BINARY_DIR}/Release/${CMAKE_FIND_LIBRARY_PREFIXES}cppformat${CMAKE_FIND_LIBRARY_SUFFIXES}" IMPORTED_LOCATION_RELEASE "${BINARY_DIR}/fmt/Release/${CMAKE_FIND_LIBRARY_PREFIXES}fmt${CMAKE_FIND_LIBRARY_SUFFIXES}"
IMPORTED_LOCATION_RELWITHDEBINFO "${BINARY_DIR}/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}cppformat${CMAKE_FIND_LIBRARY_SUFFIXES}" IMPORTED_LOCATION_RELWITHDEBINFO "${BINARY_DIR}/fmt/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}fmt${CMAKE_FIND_LIBRARY_SUFFIXES}"
IMPORTED_LOCATION_MINSIZEREL "${BINARY_DIR}/MinSizeRel/${CMAKE_FIND_LIBRARY_PREFIXES}cppformat${CMAKE_FIND_LIBRARY_SUFFIXES}") IMPORTED_LOCATION_MINSIZEREL "${BINARY_DIR}/fmt/MinSizeRel/${CMAKE_FIND_LIBRARY_PREFIXES}fmt${CMAKE_FIND_LIBRARY_SUFFIXES}")
else() else()
set(CPPFORMAT_IMPORTED_LOCATION set(FMTLIB_IMPORTED_LOCATION
IMPORTED_LOCATION "${BINARY_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}cppformat.a") IMPORTED_LOCATION "${BINARY_DIR}/fmt/${CMAKE_FIND_LIBRARY_PREFIXES}fmt.a")
endif() endif()
add_library(cppformat_import STATIC IMPORTED GLOBAL) add_library(fmtlib_import STATIC IMPORTED GLOBAL)
add_dependencies(cppformat_import cppformat) add_dependencies(fmtlib_import fmtlib)
set_target_properties(cppformat_import PROPERTIES ${CPPFORMAT_IMPORTED_LOCATION}) set_target_properties(fmtlib_import PROPERTIES ${FMTLIB_IMPORTED_LOCATION})
add_library(cppformat_final INTERFACE) add_library(fmtlib_final INTERFACE)
target_include_directories(cppformat_final INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/${CPPFORMAT_DIR}") target_include_directories(fmtlib_final INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/${FMTLIB_DIR}")
target_link_libraries(cppformat_final INTERFACE cppformat_import) target_link_libraries(fmtlib_final INTERFACE fmtlib_import)
set(CPPFORMAT_LINK cppformat_final PARENT_SCOPE) set(FMTLIB_LINK fmtlib_final PARENT_SCOPE)
# excmd # excmd
set(EXCMD_DIR "excmd") set(EXCMD_DIR "excmd")

1
externals/cppformat vendored

@ -1 +0,0 @@
Subproject commit 804ad8f4df7e01259374a1d2f458775f1b2d1164

1
externals/fmt vendored Submodule

@ -0,0 +1 @@
Subproject commit 398343897f98b88ade80bbebdcbe82a36c65a980

View File

@ -116,5 +116,6 @@ exit:
WHBUnmountSdCard(); WHBUnmountSdCard();
WHBGfxShutdown(); WHBGfxShutdown();
WHBProcShutdown(); WHBProcShutdown();
WHBLogUdpDeinit();
return result; return result;
} }

View File

@ -16,12 +16,12 @@
static int fs_translate_error(FSStatus error); static int fs_translate_error(FSStatus error);
static int fs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode); static int fs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
static int fs_close(struct _reent *r, int fd); static int fs_close(struct _reent *r, void *fd);
static ssize_t fs_write(struct _reent *r, int fd, const char *ptr, size_t len); static ssize_t fs_write(struct _reent *r, void *fd, const char *ptr, size_t len);
static ssize_t fs_write_safe(struct _reent *r, int fd, const char *ptr, size_t len); static ssize_t fs_write_safe(struct _reent *r, void *fd, const char *ptr, size_t len);
static ssize_t fs_read(struct _reent *r, int fd, char *ptr, size_t len); static ssize_t fs_read(struct _reent *r, void *fd, char *ptr, size_t len);
static off_t fs_seek(struct _reent *r, int fd, off_t pos, int dir); static off_t fs_seek(struct _reent *r, void *fd, off_t pos, int dir);
static int fs_fstat(struct _reent *r, int fd, struct stat *st); static int fs_fstat(struct _reent *r, void *fd, struct stat *st);
static int fs_stat(struct _reent *r, const char *file, struct stat *st); static int fs_stat(struct _reent *r, const char *file, struct stat *st);
static int fs_link(struct _reent *r, const char *existing, const char *newLink); static int fs_link(struct _reent *r, const char *existing, const char *newLink);
static int fs_unlink(struct _reent *r, const char *name); static int fs_unlink(struct _reent *r, const char *name);
@ -33,10 +33,10 @@ static int fs_dirreset(struct _reent *r, DIR_ITER *dirState);
static int fs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); static int fs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
static int fs_dirclose(struct _reent *r, DIR_ITER *dirState); static int fs_dirclose(struct _reent *r, DIR_ITER *dirState);
static int fs_statvfs(struct _reent *r, const char *path, struct statvfs *buf); static int fs_statvfs(struct _reent *r, const char *path, struct statvfs *buf);
static int fs_ftruncate(struct _reent *r, int fd, off_t len); static int fs_ftruncate(struct _reent *r, void *fd, off_t len);
static int fs_fsync(struct _reent *r, int fd); static int fs_fsync(struct _reent *r, void *fd);
static int fs_chmod(struct _reent *r, const char *path, mode_t mode); static int fs_chmod(struct _reent *r, const char *path, mode_t mode);
static int fs_fchmod(struct _reent *r, int fd, mode_t mode); static int fs_fchmod(struct _reent *r, void *fd, mode_t mode);
static int fs_rmdir(struct _reent *r, const char *name); static int fs_rmdir(struct _reent *r, const char *name);
/** /**
@ -292,7 +292,7 @@ fs_open(struct _reent *r,
static int static int
fs_close(struct _reent *r, fs_close(struct _reent *r,
int fd) void *fd)
{ {
FSStatus rc; FSStatus rc;
fs_file_t *file = (fs_file_t*)fd; fs_file_t *file = (fs_file_t*)fd;
@ -313,7 +313,7 @@ fs_close(struct _reent *r,
static ssize_t static ssize_t
fs_write(struct _reent *r, fs_write(struct _reent *r,
int fd, void *fd,
const char *ptr, const char *ptr,
size_t len) size_t len)
{ {
@ -373,7 +373,7 @@ fs_write(struct _reent *r,
static ssize_t static ssize_t
fs_write_safe(struct _reent *r, fs_write_safe(struct _reent *r,
int fd, void *fd,
const char *ptr, const char *ptr,
size_t len) size_t len)
{ {
@ -433,7 +433,7 @@ fs_write_safe(struct _reent *r,
static ssize_t static ssize_t
fs_read(struct _reent *r, fs_read(struct _reent *r,
int fd, void *fd,
char *ptr, char *ptr,
size_t len) size_t len)
{ {
@ -502,7 +502,7 @@ fs_read(struct _reent *r,
static off_t static off_t
fs_seek(struct _reent *r, fs_seek(struct _reent *r,
int fd, void *fd,
off_t pos, off_t pos,
int whence) int whence)
{ {
@ -565,7 +565,7 @@ fs_seek(struct _reent *r,
static int static int
fs_fstat(struct _reent *r, fs_fstat(struct _reent *r,
int fd, void *fd,
struct stat *st) struct stat *st)
{ {
FSStatus rc; FSStatus rc;
@ -613,7 +613,7 @@ fs_stat(struct _reent *r,
if (rc >= 0) { if (rc >= 0) {
fs_file_t tmpfd = { .fd = fd }; fs_file_t tmpfd = { .fd = fd };
rc = fs_fstat(r, (int)&tmpfd, st); rc = fs_fstat(r, &tmpfd, st);
FSCloseFile(fsClient, &fsCmd, fd, -1); FSCloseFile(fsClient, &fsCmd, fd, -1);
return rc; return rc;
} }
@ -940,7 +940,7 @@ fs_statvfs(struct _reent *r,
static int static int
fs_ftruncate(struct _reent *r, fs_ftruncate(struct _reent *r,
int fd, void *fd,
off_t len) off_t len)
{ {
FSStatus rc; FSStatus rc;
@ -975,7 +975,7 @@ fs_ftruncate(struct _reent *r,
static int static int
fs_fsync(struct _reent *r, fs_fsync(struct _reent *r,
int fd) void *fd)
{ {
FSStatus rc; FSStatus rc;
fs_file_t *file = (fs_file_t*)fd; fs_file_t *file = (fs_file_t*)fd;
@ -1024,7 +1024,7 @@ fs_chmod(struct _reent *r,
static int static int
fs_fchmod(struct _reent *r, fs_fchmod(struct _reent *r,
int fd, void *fd,
mode_t mode) mode_t mode)
{ {
//TODO: FSChangeMode and FSStatFile? //TODO: FSChangeMode and FSStatFile?

View File

@ -0,0 +1,29 @@
#pragma once
#include <wut.h>
/**
* \defgroup whb_commandserver Network Command Server
* \ingroup whb
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
#define WHB_SERVER_BUFFER_SIZE 1024
BOOL
WHBCommandServerInit();
void
WHBCommandServerStop();
BOOL
WHBCommandServerListen(char * stringLocation);
#ifdef __cplusplus
}
#endif
/** @} */

View File

@ -0,0 +1,27 @@
#pragma once
/**
* \defgroup whb_socketinit Socket Library Initialization Manager
* \ingroup whb
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Socket Library (nsysnet.rpl)
*/
void
WHBInitializeSocketLibrary();
void
WHBDeinitializeSocketLibrary();
#ifdef __cplusplus
}
#endif
/** @} */

View File

@ -16,9 +16,18 @@ typedef void (*LogHandlerFn)(const char *msg);
BOOL BOOL
WHBAddLogHandler(LogHandlerFn fn); WHBAddLogHandler(LogHandlerFn fn);
BOOL
WHBRemoveLogHandler(LogHandlerFn fn);
BOOL
WHBLogWrite(const char *str);
BOOL BOOL
WHBLogPrint(const char *str); WHBLogPrint(const char *str);
BOOL
WHBLogWritef(const char *fmt, ...);
BOOL BOOL
WHBLogPrintf(const char *fmt, ...); WHBLogPrintf(const char *fmt, ...);

View File

@ -14,6 +14,9 @@ extern "C" {
BOOL BOOL
WHBLogCafeInit(); WHBLogCafeInit();
BOOL
WHBLogCafeDeinit();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -14,6 +14,9 @@ extern "C" {
BOOL BOOL
WHBLogUdpInit(); WHBLogUdpInit();
BOOL
WHBLogUdpDeinit();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -0,0 +1,138 @@
#include <coreinit/baseheap.h>
#include <coreinit/expandedheap.h>
#include <nsysnet/socket.h>
#include <whb/commandserver.h>
#include <whb/libmanager.h>
#include <whb/log.h>
#include <string.h>
#define SERVER_PORT 4406
int
sSocket = -1;
int
sClient = -1;
struct sockaddr_in
sAddr;
static inline void
closeSocket(const char * funcName)
{
int ret = socketclose(sSocket);
if(ret < 0) {
WHBLogPrintf("%s: Error occurred closing socket: %d", funcName, socketlasterr());
}
else {
sSocket = -1;
}
}
static inline void
closeClient(const char * funcName)
{
int ret = socketclose(sClient);
if(ret < 0) {
WHBLogPrintf("%s: Error occurred closing client socket: %d", funcName, socketlasterr());
}
else {
sClient = -1;
}
}
BOOL
WHBCommandServerInit()
{
int ret = 0;
if(sSocket >= 0) {
WHBLogPrintf("%s: Command server is already running.", __FUNCTION__);
return TRUE;
}
WHBInitializeSocketLibrary();
sSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sSocket < 0) {
WHBLogPrintf("%s: Error occurred while creating socket: %d", __FUNCTION__, socketlasterr());
sSocket = -1;
return FALSE;
}
memset(&sAddr, 0, sizeof(struct sockaddr_in));
sAddr.sin_family = AF_INET;
sAddr.sin_port = htons(SERVER_PORT);
sAddr.sin_addr.s_addr = htonl(INADDR_ANY);
ret = bind(sSocket, (struct sockaddr *)&sAddr, sizeof(struct sockaddr_in));
if(ret < 0) {
WHBLogPrintf("%s: Error occurred while binding to socket: %d", __FUNCTION__, socketlasterr());
closeSocket(__FUNCTION__);
return FALSE;
}
ret = listen(sSocket, 3);
if(ret < 0) {
WHBLogPrintf("%s: Error occurred while setting socket to listen mode: %d", __FUNCTION__, socketlasterr());
closeSocket(__FUNCTION__);
return FALSE;
}
return TRUE;
}
void
WHBCommandServerStop()
{
if(sSocket < 0) {
WHBLogPrintf("%s: Socket is already closed.", __FUNCTION__);
return;
}
if(sClient >= 0) {
closeClient(__FUNCTION__);
}
closeSocket(__FUNCTION__);
WHBDeinitializeSocketLibrary();
}
BOOL
WHBCommandServerListen(char * stringLocation)
{
char buffer[WHB_SERVER_BUFFER_SIZE];
memset(buffer, 0, WHB_SERVER_BUFFER_SIZE);
int ret;
struct sockaddr_in sClientAddr;
socklen_t sClientAddrLen = sizeof(struct sockaddr_in);
if(sSocket < 0) {
WHBLogPrintf("%s: Socket is not open. Please run WHBCommandServerInit() first.", __FUNCTION__);
return FALSE;
}
if(sClient < 0) {
sClient = accept(sSocket, (struct sockaddr *)&sClientAddr, &sClientAddrLen);
if(sClient < 0) {
WHBLogPrintf("%s: Error occurred while accepting a client connection: %d", __FUNCTION__, socketlasterr());
return FALSE;
}
}
ret = recv(sClient, buffer, WHB_SERVER_BUFFER_SIZE, 0);
if(ret < 0) {
WHBLogPrintf("%s: Error occurred while receiving data from client: %d", __FUNCTION__, socketlasterr());
closeClient(__FUNCTION__);
return FALSE;
}
if(ret == 0) {
WHBLogPrintf("%s: Remote socket was closed. Closing client connection...", __FUNCTION__);
closeClient(__FUNCTION__);
return FALSE;
}
memcpy(stringLocation, buffer, WHB_SERVER_BUFFER_SIZE);
return TRUE;
}

View File

@ -0,0 +1,33 @@
#include <nsysnet/socket.h>
/**
* Socket Library (nsysnet.rpl)
*/
static BOOL
isSocketInitialized = FALSE;
static unsigned int
numberOfSocketClients = 0;
void
WHBInitializeSocketLibrary()
{
if(!isSocketInitialized) {
isSocketInitialized = TRUE;
socket_lib_init();
}
numberOfSocketClients++;
}
void
WHBDeinitializeSocketLibrary()
{
if(numberOfSocketClients > 0) {
numberOfSocketClients--;
}
if(isSocketInitialized && numberOfSocketClients == 0) {
isSocketInitialized = FALSE;
socket_lib_finish();
}
}

View File

@ -10,6 +10,17 @@
static LogHandlerFn static LogHandlerFn
sHandlers[MAX_HANDLERS] = { 0 }; sHandlers[MAX_HANDLERS] = { 0 };
static inline void
dispatchMessage(const char * str)
{
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) {
sHandlers[i](str);
}
}
}
BOOL BOOL
WHBAddLogHandler(LogHandlerFn fn) WHBAddLogHandler(LogHandlerFn fn)
{ {
@ -26,36 +37,85 @@ WHBAddLogHandler(LogHandlerFn fn)
} }
BOOL BOOL
WHBLogPrint(const char *str) WHBRemoveLogHandler(LogHandlerFn fn)
{ {
int i; int i;
for(i = 0; i < MAX_HANDLERS; ++i) { for(i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) { if(sHandlers[i] == fn) {
sHandlers[i](str); sHandlers[i] = NULL;
return TRUE;
} }
} }
return FALSE;
}
BOOL
WHBLogWrite(const char *str)
{
dispatchMessage(str);
return TRUE; return TRUE;
} }
BOOL BOOL
WHBLogPrintf(const char *fmt, ...) WHBLogPrint(const char *str)
{
char *buf = MEMAllocFromDefaultHeapEx(PRINTF_BUFFER_LENGTH, 4);
if(!buf) {
return FALSE;
}
snprintf(buf, PRINTF_BUFFER_LENGTH, "%s\n", str);
dispatchMessage(buf);
MEMFreeToDefaultHeap(buf);
return TRUE;
}
BOOL
WHBLogWritef(const char *fmt, ...)
{ {
char *buf = MEMAllocFromDefaultHeapEx(PRINTF_BUFFER_LENGTH, 4); char *buf = MEMAllocFromDefaultHeapEx(PRINTF_BUFFER_LENGTH, 4);
va_list va; va_list va;
BOOL result;
if (!buf) { if (!buf) {
return FALSE; return FALSE;
} }
va_start(va, fmt); va_start(va, fmt);
vsnprintf(buf, PRINTF_BUFFER_LENGTH, fmt, va); vsnprintf(buf, PRINTF_BUFFER_LENGTH, fmt, va);
result = WHBLogPrint(buf); dispatchMessage(buf);
MEMFreeToDefaultHeap(buf); MEMFreeToDefaultHeap(buf);
va_end(va); va_end(va);
return result; return TRUE;
}
BOOL
WHBLogPrintf(const char *fmt, ...)
{
char *buf1 = MEMAllocFromDefaultHeapEx(PRINTF_BUFFER_LENGTH, 4);
char *buf2 = MEMAllocFromDefaultHeapEx(PRINTF_BUFFER_LENGTH, 4);
va_list va;
if (!buf1) {
return FALSE;
}
if(!buf2) {
MEMFreeToDefaultHeap(buf1);
return FALSE;
}
va_start(va, fmt);
vsnprintf(buf1, PRINTF_BUFFER_LENGTH, fmt, va);
snprintf(buf2, PRINTF_BUFFER_LENGTH, "%s\n", buf1);
dispatchMessage(buf2);
MEMFreeToDefaultHeap(buf1);
MEMFreeToDefaultHeap(buf2);
va_end(va);
return TRUE;
} }

View File

@ -1,15 +1,29 @@
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <whb/log.h> #include <whb/log.h>
#include <string.h>
static void static void
cafeLogHandler(const char * msg) cafeLogHandler(const char * msg)
{ {
int length = strlen(msg);
if(msg[length-1] != '\n') {
OSReport("%s\n", msg); OSReport("%s\n", msg);
} }
else {
OSReport(msg);
}
}
BOOL BOOL
WHBLogCafeInit() WHBLogCafeInit()
{ {
WHBAddLogHandler(cafeLogHandler); return WHBAddLogHandler(cafeLogHandler);
return TRUE; }
BOOL
WHBLogCafeDeinit()
{
return WHBRemoveLogHandler(cafeLogHandler);
} }

View File

@ -4,6 +4,7 @@
#include <string.h> #include <string.h>
#include <whb/log.h> #include <whb/log.h>
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <whb/libmanager.h>
static int static int
sSocket = -1; sSocket = -1;
@ -28,7 +29,7 @@ BOOL
WHBLogUdpInit() WHBLogUdpInit()
{ {
int broadcastEnable = 1; int broadcastEnable = 1;
socket_lib_init(); WHBInitializeSocketLibrary();
sSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); sSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sSocket < 0) { if (sSocket < 0) {
@ -42,6 +43,16 @@ WHBLogUdpInit()
sSendAddr.sin_port = htons(SERVER_PORT); sSendAddr.sin_port = htons(SERVER_PORT);
sSendAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST); sSendAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
WHBAddLogHandler(udpLogHandler); return WHBAddLogHandler(udpLogHandler);
return TRUE; }
BOOL
WHBLogUdpDeinit()
{
if(shutdown(sSocket, SHUT_WR) != 0) {
return FALSE;
}
WHBDeinitializeSocketLibrary();
return WHBRemoveLogHandler(udpLogHandler);
} }

View File

@ -7,8 +7,8 @@ add_executable(implcheck ${SOURCE_FILES} ${HEADER_FILES})
set_target_properties(implcheck PROPERTIES FOLDER tools) set_target_properties(implcheck PROPERTIES FOLDER tools)
target_link_libraries(implcheck PRIVATE target_link_libraries(implcheck PRIVATE
${CPPFORMAT_LINK}
${EXCMD_LINK} ${EXCMD_LINK}
${FMTLIB_LINK}
${ZLIB_LINK}) ${ZLIB_LINK})
install(TARGETS implcheck RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") install(TARGETS implcheck RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

View File

@ -1,6 +1,6 @@
#include <algorithm> #include <algorithm>
#include <excmd.h> #include <excmd.h>
#include <format.h> #include <fmt/format.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector> #include <vector>

View File

@ -7,8 +7,8 @@ add_executable(readrpl ${SOURCE_FILES} ${HEADER_FILES})
set_target_properties(readrpl PROPERTIES FOLDER tools) set_target_properties(readrpl PROPERTIES FOLDER tools)
target_link_libraries(readrpl PRIVATE target_link_libraries(readrpl PRIVATE
${CPPFORMAT_LINK}
${EXCMD_LINK} ${EXCMD_LINK}
${FMTLIB_LINK}
${ZLIB_LINK}) ${ZLIB_LINK})
install(TARGETS readrpl RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") install(TARGETS readrpl RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

View File

@ -1,5 +1,5 @@
#include <excmd.h> #include <excmd.h>
#include <format.h> #include <fmt/format.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
@ -700,7 +700,7 @@ int main(int argc, char **argv)
if (header.magic != elf::HeaderMagic) { if (header.magic != elf::HeaderMagic) {
std::cout << "Invalid ELF magic header" << std::endl; std::cout << "Invalid ELF magic header" << std::endl;
return false; return -1;
} }
// Read sections // Read sections

View File

@ -90,7 +90,8 @@ int main(int argc, char **argv)
if (recvd > 0) { if (recvd > 0) {
buffer[recvd] = 0; buffer[recvd] = 0;
std::cout << buffer << std::endl; std::cout << buffer;
std::cout.flush();
} }
} }
} }