Changes

1,558 bytes added ,  02:28, 6 November 2019
no edit summary
Line 675: Line 675:  
** That func does:
 
** That func does:
 
** Gets [[System_Settings|system-setting]] <code>nim.errorsimulate!error_localcommunication_result</code>, returning that as an error if set + non-zero.
 
** Gets [[System_Settings|system-setting]] <code>nim.errorsimulate!error_localcommunication_result</code>, returning that as an error if set + non-zero.
** Does socket setup.
+
** Does socket setup:
 
** Calls a func.
 
** Calls a func.
 
** When any of the above fail (including the system-setting), the Result is written into state, then the Result is returned.
 
** When any of the above fail (including the system-setting), the Result is written into state, then the Result is returned.
Line 684: Line 684:  
*** All IDs in the below table are implemented by the server, even 0x3 for SystemUpdate.
 
*** All IDs in the below table are implemented by the server, even 0x3 for SystemUpdate.
 
*** An error is thrown if the ID is unrecognized. An error is thrown if the value of the request size1 doesn't match the expected fixed value (except for ID 0x0).
 
*** An error is thrown if the ID is unrecognized. An error is thrown if the value of the request size1 doesn't match the expected fixed value (except for ID 0x0).
 +
 +
The above socket setup for the Send async thread does the following:
 +
* Clears sockaddr_in and sets addrlen to 0x10.
 +
* Enters a loop which repeatedly calls a func. If that func fails, this will immediately return.
 +
* Within that loop the following is done:
 +
** sockfd = accept(listen_sockfd, &sockaddr_in, &addrlen); {handle error on fail - listen_sockfd is the saved sockfd from [[#Cmd76]]}
 +
** Exits the loop when the ipaddr within sockaddr_in matches the saved ipaddr in state from [[#Cmd76]] (originally from the cmd input param). Otherwise, close sockfd and continue the loop (with the above func being called again).
 +
* The following is done after the loop:
 +
* u64 tmpval=1; setsockopt(sockfd, SOL_SOCKET, SO_VENDOR + 0x1, &tmpval, sizeof(tmpval)); {handle error on fail}
 +
* Uses a service cmd, returning an error if this is successful. Hence, the output from this is ignored.
 +
* Uses fcntl with F_GETFL/F_SETFL to clear O_NONBLOCK with sockfd, handling error on fail.
 +
* u32 tmpval2=0x4000;
 +
* u32 tmpval3=0x20000;
 +
* setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &tmpval2, sizeof(tmpval2)); {error is ignored}
 +
* setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &tmpval3, sizeof(tmpval3)); {error is ignored}
 +
* Writes sockfd to the output state sockfd and returns 0.
 +
** The func used with the above loop does the following:
 +
** Uses select() with input setup for {content of readfds = sockfd}, and timeval setup for a 1-second timeout. This is used repeatedly, until this returns an error (in which case error handling is done) or returns non-zero.
 +
** Then this returns 0.
    
Messages (requests/replies) begin with the following 0x10-byte header, then any associated data.
 
Messages (requests/replies) begin with the following 0x10-byte header, then any associated data.