moonbridge
changeset 71:4628be0a7b98
Updated reference to include xread, xread_nb, write_nb
author | jbe |
---|---|
date | Sat Apr 04 21:28:30 2015 +0200 (2015-04-04) |
parents | 360a1860bb14 |
children | 7764a1fd85e7 |
files | reference.txt |
line diff
1.1 --- a/reference.txt Sat Apr 04 21:11:15 2015 +0200 1.2 +++ b/reference.txt Sat Apr 04 21:28:30 2015 +0200 1.3 @@ -110,36 +110,32 @@ 1.4 Supports the same methods as io.open()'s return values. 1.5 1.6 1.7 -### socket.input:pending() 1.8 - 1.9 -Returns true if there is at least one byte to read. In case of I/O errors, true 1.10 -is returned as well (to avoid lockup and cause error on subsequent read). 1.11 +### socket.input:xread(maxlen, terminator) 1.12 1.13 -Note: Subsequent calls of socket.input:read(...) or socket.input:readuntil(...) 1.14 -may still block when attempting to read more than one byte. To avoid hanging 1.15 -processes, the timeout(...) function may be used as a watchdog that will 1.16 -terminate the process in case of unexpected delay. Because file handles are 1.17 -buffered, data may be still pending even if the underlaying file descriptor 1.18 -does not have any more data to read. Thus, all file handles passed to 1.19 -io.poll(...) to wait for reading should be tested for pending data first. 1.20 +Reads as many bytes until either the maximum length is reached (first argument) 1.21 +or a terminating character (second argument as string with a length of 1) is 1.22 +encountered. In the latter case, the terminating character will be included in 1.23 +the result. 1.24 1.25 -This method is also available as :pending() for any other Lua file handle. 1.26 +On EOF, false (as first result value) and an error message (as second result 1.27 +value) are returned. In case of an I/O error, nil and an error message are 1.28 +returned. 1.29 + 1.30 +This method is also available for any other Lua file handle. 1.31 1.32 1.33 -### socket.input:readuntil(terminator, maxlen) 1.34 +### socket.input:xread_nb(maxlen, terminator) 1.35 1.36 -Reads as many bytes until a byte equal to the terminator value occurs. An 1.37 -optional maximum length may be specified. The terminating byte is included in 1.38 -the return value (unless the maximum length would be exceeded). On EOF, nil is 1.39 -returned. In case of an I/O error, nil (as first result value) plus an error 1.40 -message (as second result value) is returned. 1.41 +Same as socket.input:xread(maxlen, terminator), but non-blocking. If no more 1.42 +data can be read due to blocking, this method returns a string containing the 1.43 +data which has already been read. If no data could be read due to blocking, 1.44 +then an empty string is returned. 1.45 1.46 -Note: This function may provide a significant speedup compared to byte-wise 1.47 -reading using socket.input:read(1) in a loop. However, this function will block 1.48 -when no data is available. The timeout(...) function may be used as a watchdog 1.49 -that will terminate the process in case of unexpected delay. 1.50 +On EOF, false (as first result value) and an error message (as second result 1.51 +value) are returned. In case of an I/O error, nil and an error message are 1.52 +returned. 1.53 1.54 -This method is also available as :readuntil(...) for any other Lua file handle. 1.55 +This method is also available for any other Lua file handle. 1.56 1.57 1.58 ### socket.interval 1.59 @@ -187,16 +183,24 @@ 1.60 transmitted data. 1.61 1.62 1.63 +### socket.output:write_nb(...) 1.64 + 1.65 +Non-blocking write. This function attempts to write as many bytes as possible, 1.66 +returning a string containing all data that could not be written due to 1.67 +blocking (potentially concatenating some or all remaining arguments to create 1.68 +that string). 1.69 + 1.70 +In case of an I/O error, nil (as first result value) and an error message (as 1.71 +second result value) are returned. 1.72 + 1.73 +This method is also available for any other Lua file handle. 1.74 + 1.75 + 1.76 ### socket:read(...) 1.77 1.78 Alias for socket.input:read() 1.79 1.80 1.81 -### socket:readuntil(terminator, maxlen) 1.82 - 1.83 -Alias for socket.input:readuntil(terminator, maxlen) 1.84 - 1.85 - 1.86 ### socket.remote_ip4 1.87 1.88 Remote IPv4 address used for the connection. Encoded as 4 raw bytes in form of 1.89 @@ -219,6 +223,21 @@ 1.90 Alias for socket.output:write(...) 1.91 1.92 1.93 +### socket:write_nb(...) 1.94 + 1.95 +Alias for socket.output:write(...) 1.96 + 1.97 + 1.98 +### socket:xread(maxlen, terminator) 1.99 + 1.100 +Alias for socket.input:xread(...) 1.101 + 1.102 + 1.103 +### socket:xread_nb(maxlen, terminator) 1.104 + 1.105 +Alias for socket.input:xread_nb(...) 1.106 + 1.107 + 1.108 1.109 HTTP module 1.110 -----------