Skip to content

Commit 53feadc

Browse files
authored
lib-socket: implement getsockopt(SOL_SOCKET,SO_TYPE) (#4458)
cf. #4456
1 parent 5d48cfd commit 53feadc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ get_sol_socket_option(int sockfd, int optname, void *__restrict optval,
610610
uint64_t timeout_us;
611611
bool is_linger_enabled;
612612
int linger_s;
613+
__wasi_fdstat_t sb;
613614

614615
switch (optname) {
615616
case SO_RCVTIMEO:
@@ -662,6 +663,22 @@ get_sol_socket_option(int sockfd, int optname, void *__restrict optval,
662663
error = __wasi_sock_get_broadcast(sockfd, (bool *)optval);
663664
HANDLE_ERROR(error);
664665
return error;
666+
case SO_TYPE:
667+
assert(*optlen == sizeof(int));
668+
error = __wasi_fd_fdstat_get(sockfd, &sb);
669+
HANDLE_ERROR(error);
670+
switch (sb.fs_filetype) {
671+
case __WASI_FILETYPE_SOCKET_DGRAM:
672+
*(int *)optval = SOCK_DGRAM;
673+
break;
674+
case __WASI_FILETYPE_SOCKET_STREAM:
675+
*(int *)optval = SOCK_STREAM;
676+
break;
677+
default:
678+
errno = __WASI_ERRNO_NOTSOCK;
679+
return -1;
680+
}
681+
return 0;
665682
default:
666683
error = __WASI_ERRNO_NOTSUP;
667684
HANDLE_ERROR(error);

0 commit comments

Comments
 (0)