Skip to content

Commit

Permalink
working on, udp socket support
Browse files Browse the repository at this point in the history
  • Loading branch information
objeck committed Dec 8, 2024
1 parent 5a6a95f commit 5152bd2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
15 changes: 11 additions & 4 deletions core/vm/arch/win32/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,20 @@ class UDPSocket {
}

static char ReadByte(struct sockaddr_in* addr_in) {
char value;
char value[512];



SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sock != INVALID_SOCKET) {
int addr_in_size = sizeof(struct sockaddr_in);
if(recvfrom(sock, &value, 1, 0, (SOCKADDR*)&addr_in, &addr_in_size)) {
return value;
// int addr_in_size = sizeof(struct sockaddr_in);

struct sockaddr_in cli_addr;
int cli_addr_size = sizeof(struct sockaddr_in);
memset(&cli_addr, 0, cli_addr_size);

if(recvfrom(sock, value, 511, 0, (SOCKADDR*)&cli_addr, &cli_addr_size) != SOCKET_ERROR) {
return 101;
}
}

Expand Down
14 changes: 4 additions & 10 deletions core/vm/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4400,16 +4400,10 @@ bool TrapProcessor::SockUdpCloseCreate(StackProgram* program, size_t* inst, size

bool TrapProcessor::SockUdpCloseBind(StackProgram* program, size_t* inst, size_t*& op_stack, long*& stack_pos, StackFrame* frame) {
if(inst) {
struct sockaddr_in* serv_addr = (struct sockaddr_in*)inst[1];
if(serv_addr) {
delete serv_addr;
serv_addr = nullptr;
}

struct sockaddr_in* cli_addr = (struct sockaddr_in*)inst[2];
if(cli_addr) {
delete cli_addr;
cli_addr = nullptr;
struct sockaddr_in* sock_addr = (struct sockaddr_in*)inst[0];
if(sock_addr) {
delete sock_addr;
sock_addr = nullptr;
}
}

Expand Down
14 changes: 7 additions & 7 deletions programs/tests/prgm328.obs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class Udp {
}
}

function : DoClient() ~ Nil {
client := UDPSocket->New("127.0.0.1", 6017);
client->WriteByte(101);
client->Close();
}

function : DoServer() ~ Nil {
server := UDPSocketServer->New(6017);
server := UDPSocketServer->New(6021);
server->Bind();
server->ReadByte()->PrintLine();
server->Close();
}

function : DoClient() ~ Nil {
client := UDPSocket->New("127.0.0.1", 6021);
client->WriteByte(101);
client->Close();
}
}

0 comments on commit 5152bd2

Please sign in to comment.