@@ -1891,10 +1891,10 @@ convert_timestamp(__wasi_timestamp_t in, os_timespec *out)
18911891#else
18921892 out -> tv_nsec = (long )(in % 1000000000 );
18931893#endif
1894- in /= 1000000000 ;
1894+ __wasi_timestamp_t temp = in / 1000000000 ;
18951895
18961896 // Clamp to the maximum in case it would overflow our system's time_t.
1897- out -> tv_sec = (time_t )in < BH_TIME_T_MAX ? (time_t )in : BH_TIME_T_MAX ;
1897+ out -> tv_sec = (time_t )temp < BH_TIME_T_MAX ? (time_t )temp : BH_TIME_T_MAX ;
18981898}
18991899
19001900__wasi_errno_t
@@ -2081,7 +2081,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
20812081 size_t nsubscriptions ,
20822082 size_t * nevents ) NO_LOCK_ANALYSIS
20832083{
2084- #if defined(BH_PLATFORM_WINDOWS ) || defined( BH_PLATFORM_ZEPHYR )
2084+ #if defined(BH_PLATFORM_WINDOWS )
20852085 return __WASI_ENOSYS ;
20862086#else
20872087 // Sleeping.
@@ -2199,7 +2199,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
21992199 if (error == 0 ) {
22002200 // Proper file descriptor on which we can poll().
22012201 pfds [i ] = (os_poll_file_handle ){
2202- .fd = fos [i ]-> file_handle ,
2202+ .fd = fos [i ]-> file_handle -> fd ,
22032203 .events = s -> u .type == __WASI_EVENTTYPE_FD_READ
22042204 ? POLLIN
22052205 : POLLOUT ,
@@ -2832,25 +2832,37 @@ wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds,
28322832{
28332833 struct fd_object * fo ;
28342834 __wasi_errno_t error ;
2835- bh_sockaddr_t sockaddr ;
2835+ bh_sockaddr_t sockaddr , * sockaddr_ptr = NULL ;
28362836 int ret ;
28372837
28382838 error = fd_object_get (curfds , & fo , sock , __WASI_RIGHT_FD_READ , 0 );
28392839 if (error != 0 ) {
28402840 return error ;
28412841 }
28422842
2843- wasi_addr_to_bh_sockaddr (src_addr , & sockaddr );
2843+ // If the source address is not NULL, the caller is requesting the source
2844+ // address to be returned if the protocol supports it. As such, we convert
2845+ // the format of the structure pass in prior to the call to the OS
2846+ // implementation. If the value is NULL, the POSIX standard states that
2847+ // the address is not returned.
2848+ if (src_addr != NULL ) {
2849+ sockaddr_ptr = & sockaddr ;
2850+ wasi_addr_to_bh_sockaddr (src_addr , & sockaddr );
2851+ }
28442852
28452853 /* Consume bh_sockaddr_t instead of __wasi_addr_t */
28462854 ret = blocking_op_socket_recv_from (exec_env , fo -> file_handle , buf , buf_len ,
2847- 0 , & sockaddr );
2855+ 0 , sockaddr_ptr );
28482856 fd_object_release (exec_env , fo );
28492857 if (-1 == ret ) {
28502858 return convert_errno (errno );
28512859 }
28522860
2853- bh_sockaddr_to_wasi_addr (& sockaddr , src_addr );
2861+ // If the source address is not NULL, we need to convert the sockaddr
2862+ // back to __wasi_addr_t format.
2863+ if (src_addr != NULL ) {
2864+ bh_sockaddr_to_wasi_addr (sockaddr_ptr , src_addr );
2865+ }
28542866
28552867 * recv_len = (size_t )ret ;
28562868 return __WASI_ESUCCESS ;
0 commit comments