Pine64 Updates.

This commit is contained in:
kpl 2020-10-31 14:17:43 -04:00
parent 635b673492
commit 96b3b1ac0a
7 changed files with 51 additions and 33 deletions

View File

@ -273,12 +273,11 @@ char* cw::filesys::expandPath( const char* dir )
cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr ) cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
{ {
unsigned n = 0; // char's in pathStr unsigned n = 0; // char's in pathStr
unsigned dn = 0; // char's in the dir part unsigned dn = 0; // char's in the dir part
unsigned fn = 0; // char's in the name part unsigned fn = 0; // char's in the name part
unsigned en = 0; // char's in the ext part unsigned en = 0; // char's in the ext part
char* cp = nullptr; char* cp = nullptr;
pathPart_t* rp = nullptr; pathPart_t* rp = nullptr;
if( pathStr==nullptr ) if( pathStr==nullptr )
return nullptr; return nullptr;
@ -352,13 +351,13 @@ cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
n = sizeof(pathPart_t) + dn + fn + en + 3; n = sizeof(pathPart_t) + dn + fn + en + 3;
// alloc memory // alloc memory
if((rp = mem::allocZ<pathPart_t>( n )) == nullptr ) if((rp = (pathPart_t*)mem::allocZ<char>( n )) == nullptr )
{ {
cwLogError( kMemAllocFailRC, "Unable to allocate the file system path part record for '%s'.",pathStr); cwLogError( kMemAllocFailRC, "Unable to allocate the file system path part record for '%s'.",pathStr);
return nullptr; goto errLabel;
} }
// set the return pointers for ecmh of the parts // set the return pointers for each of the parts
rp->dirStr = (const char* )(rp + 1); rp->dirStr = (const char* )(rp + 1);
rp->fnStr = rp->dirStr + dn + 1; rp->fnStr = rp->dirStr + dn + 1;
rp->extStr = rp->fnStr + fn + 1; rp->extStr = rp->fnStr + fn + 1;
@ -375,7 +374,7 @@ cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
// Get the trailing word again. // Get the trailing word again.
// pathStr must be copied into a buf because basename() may // pathStr must be copied into a buf because basename() may
// is allowed to change the values in its arg. // is allowed to change the values in its arg.
strncpy(buf,pathStr,n); strcpy(buf,pathStr);
cp = basename(buf); cp = basename(buf);
@ -405,6 +404,7 @@ cw::filesys::pathPart_t* cw::filesys::pathParts( const char* pathStr )
if( en == 0 ) if( en == 0 )
rp->extStr = nullptr; rp->extStr = nullptr;
errLabel:
return rp; return rp;
} }

View File

@ -6,17 +6,17 @@
void* cw::mem::_alloc( void* p0, unsigned n, unsigned flags ) void* cw::mem::_alloc( void* p0, unsigned n, unsigned flags )
{ {
void* p = nullptr; // ptr to new block void* p = nullptr; // ptr to new block
unsigned p0N = 0; // size of existing block unsigned p0N = 0; // size of existing block
unsigned* p0_1 = nullptr; // pointer to base of existing block unsigned* p0_1 = nullptr; // pointer to base of existing block
n += sizeof(unsigned); // add space for the size of the block n += 2*sizeof(unsigned); // add space for the size of the block
// if there is no existing block // if there is no existing block
if( p0 != nullptr ) if( p0 != nullptr )
{ {
// get a pointer to the base of the exsting block // get a pointer to the base of the exsting block
p0_1 = ((unsigned*)p0) - 1; p0_1 = ((unsigned*)p0) - 2;
p0N = p0_1[0]; // get size of existing block p0N = p0_1[0]; // get size of existing block
@ -49,7 +49,13 @@ void* cw::mem::_alloc( void* p0, unsigned n, unsigned flags )
p1[0] = n; // set size of new block p1[0] = n; // set size of new block
// advance past the block size and return // advance past the block size and return
return p1+1; return p1+2;
/*
n += 8;
char* p = (char*)calloc(1,n);
return p+8;
*/
} }
@ -96,6 +102,6 @@ void cw::mem::free( void* p )
{ {
if( p != nullptr) if( p != nullptr)
{ {
::free(static_cast<unsigned*>(p)-1); ::free(static_cast<unsigned*>(p)-2);
} }
} }

View File

@ -12,10 +12,10 @@ namespace cw
{ {
typedef struct spsc_buf_str typedef struct spsc_buf_str
{ {
uint8_t* buf;
unsigned bufByteN;
std::atomic<uint8_t*> w; // write ptr std::atomic<uint8_t*> w; // write ptr
std::atomic<uint8_t*> r; // read ptr std::atomic<uint8_t*> r; // read ptr
uint8_t* buf;
unsigned bufByteN;
} spsc_buf_t; } spsc_buf_t;
// Note: r==w indicates an empty buffer. // Note: r==w indicates an empty buffer.
@ -57,11 +57,11 @@ cw::rc_t cw::spsc_buf::create( handle_t& hRef, unsigned bufByteN )
return rc; return rc;
spsc_buf_t* p = mem::allocZ<spsc_buf_t>(); spsc_buf_t* p = mem::allocZ<spsc_buf_t>();
p->buf = mem::allocZ<uint8_t>(bufByteN); p->buf = mem::allocZ<uint8_t>(bufByteN);
p->bufByteN = bufByteN; p->bufByteN = bufByteN;
p->w = p->buf; p->w.store(p->buf);
p->r = p->buf; p->r.store(p->buf);
hRef.set(p); hRef.set(p);
return rc; return rc;
@ -392,7 +392,9 @@ cw::rc_t cw::spsc_buf::test()
// create the SPSC buffer // create the SPSC buffer
if((rc = create( share.h, bufByteN )) != kOkRC ) if((rc = create( share.h, bufByteN )) != kOkRC )
{
return cwLogError(rc,"spsc_buf create failed."); return cwLogError(rc,"spsc_buf create failed.");
}
// create the thread machine // create the thread machine
if((rc = thread_mach::create( h, _threadFunc, ctxArray, sizeof(ctx_t), ctxArrayN )) != kOkRC ) if((rc = thread_mach::create( h, _threadFunc, ctxArray, sizeof(ctx_t), ctxArrayN )) != kOkRC )

View File

@ -163,6 +163,7 @@ cw::rc_t cw::testSpScQueueTmpl()
goto errLabel; goto errLabel;
} }
cwLogInfo("running for 1 minute ...");
sleepMs(60 * 1000); sleepMs(60 * 1000);
errLabel: errLabel:

View File

@ -3,11 +3,11 @@
#include "cwCommonImpl.h" #include "cwCommonImpl.h"
#include "cwMem.h" #include "cwMem.h"
#include "cwThread.h" #include "cwThread.h"
#include "cwObject.h"
#include "cwWebSock.h" #include "cwWebSock.h"
#include "cwWebSockSvr.h" #include "cwWebSockSvr.h"
#include "cwText.h" #include "cwText.h"
#include "cwNumericConvert.h" #include "cwNumericConvert.h"
#include "cwObject.h"
#include "cwUi.h" #include "cwUi.h"

View File

@ -4,8 +4,10 @@
#include "cwMem.h" #include "cwMem.h"
#include "cwWebSock.h" #include "cwWebSock.h"
#include "cwThread.h" #include "cwThread.h"
#include "cwObject.h"
#include "cwWebSockSvr.h" #include "cwWebSockSvr.h"
#include "cwText.h" #include "cwText.h"
#include "cwFileSys.h"
namespace cw namespace cw
{ {
@ -71,6 +73,8 @@ cw::rc_t cw::websockSrv::create(
p->_timeOutMs = timeOutMs; p->_timeOutMs = timeOutMs;
cwLogInfo("Listening on port:%i root dir:%s default page:%s\n", port, cwStringNullGuard(physRootDir), cwStringNullGuard(dfltHtmlPageFn));
h.set(p); h.set(p);
errLabel: errLabel:
@ -162,12 +166,12 @@ namespace cw
} }
cw::rc_t cw::websockSrvTest() cw::rc_t cw::websockSrvTest( const object_t* cfg )
{ {
rc_t rc; rc_t rc;
websockSrv::handle_t h; websockSrv::handle_t h;
const char* physRootDir = "/home/kevin/src/cwtest/src/libcw/html/websockSrvTest"; const char* physRootDirArg = nullptr; //"/home/kevin/src/cwtest/src/libcw/html/websockSrvTest";
const char* dfltHtmlPageFn = "test_websocket.html"; const char* dfltHtmlPageFn = nullptr; //"test_websocket.html";
unsigned timeOutMs = 50; unsigned timeOutMs = 50;
int port = 5687; int port = 5687;
unsigned rcvBufByteN = 128; unsigned rcvBufByteN = 128;
@ -186,6 +190,11 @@ cw::rc_t cw::websockSrvTest()
{ "websocksrv_test_protocol",kWebsockSrvProtocolId,rcvBufByteN,xmtBufByteN} { "websocksrv_test_protocol",kWebsockSrvProtocolId,rcvBufByteN,xmtBufByteN}
}; };
if((rc = cfg->getv("physRootDir",physRootDirArg,"dfltHtmlPageFn",dfltHtmlPageFn)) != kOkRC )
return cwLogError(rc,"Args parse failed.");
char* physRootDir = cw::filesys::expandPath(physRootDirArg);
unsigned protocolN = sizeof(protocolA)/sizeof(protocolA[0]); unsigned protocolN = sizeof(protocolA)/sizeof(protocolA[0]);

View File

@ -31,7 +31,7 @@ namespace cw {
} }
rc_t websockSrvTest(); rc_t websockSrvTest( const object_t* cfg );
} }
#endif #endif