Skip to content

Commit 506b42e

Browse files
committed
refactor
1 parent e8641ba commit 506b42e

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

mrbgems/picoruby-net/include/net.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,10 @@
1616
extern "C" {
1717
#endif
1818

19-
//typedef struct {
20-
// char *data;
21-
// size_t len;
22-
//} recv_data_t;
23-
//
24-
//#if !defined(sleep_ms)
25-
//int sleep_ms(long milliseconds);
26-
//#endif
2719
void lwip_begin(void);
2820
void lwip_end(void);
2921
void Net_sleep_ms(int);
30-
//
3122
err_t Net_get_ip(const char *name, ip_addr_t *ip);
32-
//void TCPClient_send(void *mrb, const char *host, int port, const char *send_data, size_t send_data_len, bool is_tls, recv_data_t *recv_data);
33-
//void UDPClient_send(void *mrb, const char *host, int port, const char *send_data, size_t send_data_len, bool is_dtls, recv_data_t *recv_data);
3423

3524
mrb_value DNS_resolve(mrb_state *mrb, const char *name, bool is_tcp);
3625
mrb_value TCPClient_send(const char *host, int port, mrb_state *mrb, mrb_value send_data, bool is_tls);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <unistd.h>
2+
#include <fcntl.h>
3+
#include <unistd.h>
4+
#include <sys/types.h>
5+
#include <sys/stat.h>
6+
#include <stdlib.h>
7+
#include <errno.h>
8+
9+
10+
void
11+
Net_sleep_ms(int ms)
12+
{
13+
usleep(ms * 1000);
14+
}
15+
16+
void
17+
lwip_begin(void)
18+
{
19+
// no-op
20+
}
21+
22+
void
23+
lwip_end(void)
24+
{
25+
// no-op
26+
}
27+
28+
int
29+
mbedtls_hardware_poll(void *data __attribute__((unused)), unsigned char *output, size_t len, size_t *olen)
30+
{
31+
int fd = open("/dev/urandom", O_RDONLY);
32+
if (fd == -1) {
33+
return -1; // Error opening /dev/urandom
34+
}
35+
36+
ssize_t bytes_read = read(fd, output, len);
37+
if (bytes_read < 0) {
38+
close(fd);
39+
return -1; // Error reading from /dev/urandom
40+
}
41+
42+
close(fd);
43+
44+
// Set the number of bytes written to the output
45+
if (olen != NULL) {
46+
*olen = bytes_read;
47+
}
48+
49+
return 0; // Success
50+
}

mrbgems/picoruby-net/src/net.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ Net_get_ip(const char *name, ip_addr_t *ip)
4242

4343
#elif defined(PICORB_VM_MRUBYC)
4444

45-
//#include "mrubyc/net.c"
46-
int mbedtls_hardware_poll (void *data, unsigned char *output, size_t len, size_t *olen){
47-
return 0;
48-
}
4945
void mrbc_net_init(mrbc_vm *vm){}
5046

47+
//TODO
48+
//#include "mrubyc/dns.c"
49+
//#include "mrubyc/net.c"
50+
//#include "mrubyc/tcp.c"
51+
//#include "mrubyc/udp.c"
52+
5153
#endif

0 commit comments

Comments
 (0)