support ioctl-FIONREAD
This commit is contained in:
Родитель
46b3356e48
Коммит
32e88a57eb
|
@ -6368,6 +6368,7 @@ LibraryManager.library = {
|
|||
connect__deps: ['$Sockets', '_inet_ntop_raw', 'ntohs'],
|
||||
connect: function(fd, addr, addrlen) {
|
||||
var info = Sockets.fds[fd];
|
||||
if (!info) return -1;
|
||||
info.connected = true;
|
||||
info.addr = getValue(addr + Sockets.sockaddr_in_layout.sin_addr, 'i32');
|
||||
info.port = _ntohs(getValue(addr + Sockets.sockaddr_in_layout.sin_port, 'i16'));
|
||||
|
@ -6396,6 +6397,7 @@ LibraryManager.library = {
|
|||
recv__deps: ['$Sockets'],
|
||||
recv: function(fd, buf, len, flags) {
|
||||
var info = Sockets.fds[fd];
|
||||
if (!info) return -1;
|
||||
if (info.bufferWrite == info.bufferRead) {
|
||||
___setErrNo(ERRNO_CODES.EAGAIN); // no data, and all sockets are nonblocking, so this is the right behavior
|
||||
return 0; // should this be -1 like the spec says?
|
||||
|
@ -6412,10 +6414,23 @@ LibraryManager.library = {
|
|||
},
|
||||
|
||||
shutdown: function(fd, how) {
|
||||
Sockets.fds[fd].socket.close();
|
||||
var info = Sockets.fds[fd];
|
||||
if (!info) return -1;
|
||||
info.socket.close();
|
||||
Sockets.fds[fd] = null;
|
||||
},
|
||||
|
||||
ioctl: function(fd, request, varargs) {
|
||||
var info = Sockets.fds[fd];
|
||||
if (!info) return -1;
|
||||
var start = info.bufferRead;
|
||||
var end = info.bufferWrite;
|
||||
if (end < start) end += Sockets.BUFFER_SIZE;
|
||||
var dest = {{{ makeGetValue('varargs', '0', 'i32') }}};
|
||||
{{{ makeSetValue('dest', '0', 'end - start', 'i32') }}};
|
||||
return 0;
|
||||
},
|
||||
|
||||
// ==========================================================================
|
||||
// emscripten.h
|
||||
// ==========================================================================
|
||||
|
|
|
@ -1126,6 +1126,7 @@ var C_DEFINES = {'SI_MESGQ': '5',
|
|||
'_CS_POSIX_V7_LP64_OFF64_LDFLAGS': '10',
|
||||
'_SC_TTY_NAME_MAX': '41',
|
||||
'AF_INET': '1',
|
||||
'AF_INET6': '6'
|
||||
'AF_INET6': '6',
|
||||
'FIONREAD': '1'
|
||||
};
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ extern "C" {
|
|||
#define TIOCGSIZE 80 // bogus
|
||||
#define TIOCGWINSZ 80 // bogus
|
||||
|
||||
#define FIONREAD 1
|
||||
|
||||
int ioctl(int d, int request, ...);
|
||||
|
||||
#define SO_RCVTIMEO 1000
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#if EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
@ -17,8 +18,11 @@ int SocketFD;
|
|||
|
||||
unsigned int get_all_buf(int sock, char* output, unsigned int maxsize)
|
||||
{
|
||||
char buffer[1024];
|
||||
int bytes;
|
||||
if (ioctl(sock, FIONREAD, &bytes)) return 0;
|
||||
if (bytes == 0) return 0;
|
||||
|
||||
char buffer[1024];
|
||||
int n;
|
||||
unsigned int offset = 0;
|
||||
while((errno = 0, (n = recv(sock, buffer, sizeof(buffer), 0))>0) ||
|
||||
|
|
Загрузка…
Ссылка в новой задаче