Skip to content

Commit 4bd4aed

Browse files
committed
upgrade ws client/server
1 parent cef324a commit 4bd4aed

24 files changed

Lines changed: 570 additions & 247 deletions

noson/src/filepicreader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "filepicreader.h"
2222
#include "private/debug.h"
2323
#include "private/tokenizer.h"
24-
#include "private/urlencoder.h"
24+
#include "private/uriencoder.h"
2525
#include "private/byteorder.h"
2626
#include "private/base64.h"
2727

noson/src/filestreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include "imageservice.h"
2121
#include "data/datareader.h"
2222
#include "private/debug.h"
23-
#include "private/urlencoder.h"
23+
#include "private/builtin.h"
24+
#include "private/uriencoder.h"
2425
#include "private/tokenizer.h"
2526
#include "private/wsstatic.h"
2627
#include "private/wsrequestbroker.h"

noson/src/imageservice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "private/debug.h"
2121
#include "data/datareader.h"
2222
#include "filepicreader.h"
23-
#include "private/urlencoder.h"
23+
#include "private/uriencoder.h"
2424
#include "private/wsstatic.h"
2525
#include "private/wsrequestbroker.h"
2626
#include "private/wsrequestreply.h"

noson/src/private/builtin.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ void char_to_hex(char c, BUILTIN_BUFFER *str)
249249
p[2] = '\0';
250250
}
251251

252+
void char_to_uhex(char c, BUILTIN_BUFFER *str)
253+
{
254+
static const char g[16] = {
255+
'0', '1', '2', '3', '4', '5', '6', '7',
256+
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
257+
};
258+
char * p = str->data;
259+
p[0] = g[(0xf & (c >> 4))];
260+
p[1] = g[(0xf & (c))];
261+
p[2] = '\0';
262+
}
263+
252264
unsigned uint_to_strdec(unsigned u, char *str, unsigned len, int pad)
253265
{
254266
static const char g[10] = {

noson/src/private/builtin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ extern int hex_to_num(const char *str, int *num);
7070
#define char_to_hex __charhex
7171
extern void char_to_hex(char c, BUILTIN_BUFFER *str);
7272

73+
#define char_to_uhex __charuhex
74+
extern void char_to_uhex(char c, BUILTIN_BUFFER *str);
75+
7376
#define int64_to_string __int64str
7477
static CC_INLINE void int64_to_string(int64_t num, BUILTIN_BUFFER *str)
7578
{

noson/src/private/pathencoder.h

Lines changed: 0 additions & 83 deletions
This file was deleted.

noson/src/private/securesocket.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,36 @@ size_t SecureSocket::ReceiveData(void* buf, size_t n)
347347
return 0;
348348
}
349349

350+
size_t SecureSocket::BlockingRead(void* buf, size_t n)
351+
{
352+
if (m_connected && n > 0)
353+
{
354+
m_ssl_error = SSL_ERROR_NONE;
355+
for (;;)
356+
{
357+
int r = SSL_read(static_cast<SSL*>(m_ssl), buf, (int) n);
358+
if (r >= 0)
359+
return (size_t) r;
360+
int err = SSL_get_error(static_cast<SSL*>(m_ssl), r);
361+
if (err == SSL_ERROR_WANT_READ)
362+
{
363+
DBG(DBG_DEBUG, "%s: SSL retry\n", __FUNCTION__);
364+
continue;
365+
}
366+
if (err == SSL_ERROR_WANT_WRITE)
367+
{
368+
DBG(DBG_DEBUG, "%s: SSL wants write\n", __FUNCTION__);
369+
m_ssl_error = ERR_get_error();
370+
break;
371+
}
372+
m_ssl_error = ERR_get_error();
373+
DBG(DBG_ERROR, "%s: SSL read failed: %s\n", __FUNCTION__, GetSSLError());
374+
break;
375+
}
376+
}
377+
return 0;
378+
}
379+
350380
bool SecureSocket::SendData(const char* buf, size_t size)
351381
{
352382
if (m_connected && size > 0)
@@ -484,6 +514,13 @@ size_t SecureSocket::ReceiveData(void* buf, size_t n)
484514
return 0;
485515
}
486516

517+
size_t SecureSocket::BlockingRead(void* buf, size_t n)
518+
{
519+
(void)buf;
520+
(void)n;
521+
return 0;
522+
}
523+
487524
bool SecureSocket::SendData(const char* buf, size_t size)
488525
{
489526
(void)buf;

noson/src/private/securesocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace NSROOT
111111
bool Connect(const char *server, unsigned port, int rcvbuf);
112112
bool SendData(const char* buf, size_t size);
113113
size_t ReceiveData(void* buf, size_t n);
114+
size_t BlockingRead(void* buf, size_t n);
114115
void Disconnect();
115116

116117
bool IsCertificateValid(std::string& info);

noson/src/private/socket.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,31 @@ size_t TcpSocket::ReceiveData(void *buf, size_t n)
414414
return 0;
415415
}
416416

417+
size_t TcpSocket::BlockingRead(void *buf, size_t n)
418+
{
419+
if (IsValid() && n > 0)
420+
{
421+
// Check for data remaining in buffer
422+
if (m_buffer)
423+
{
424+
if (m_bufptr < m_buffer + m_rcvlen)
425+
{
426+
size_t rcvlen = m_rcvlen - (m_bufptr - m_buffer);
427+
if (rcvlen > n)
428+
rcvlen = n;
429+
memcpy(buf, m_bufptr, rcvlen);
430+
m_bufptr += rcvlen;
431+
return rcvlen;
432+
}
433+
}
434+
435+
int r = 0;
436+
if ((r = recv(m_socket, buf, n, 0)) > 0)
437+
return r;
438+
}
439+
return 0;
440+
}
441+
417442
void TcpSocket::Disconnect()
418443
{
419444
if (IsValid())

noson/src/private/socket.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ namespace NSROOT
107107
*/
108108
virtual size_t ReceiveData(void* buf, size_t n);
109109

110+
/**
111+
* Read data or block.
112+
* @param buf the pointer to write data
113+
* @param n read at most n bytes
114+
* @return the number of received byte
115+
*/
116+
virtual size_t BlockingRead(void* buf, size_t n);
117+
110118
/**
111119
* Gracefully disconnect the socket.
112120
*/

0 commit comments

Comments
 (0)