aboutsummaryrefslogtreecommitdiff
path: root/jim-aio.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-15improve portability of bootstrap jimshSteve Bennett1-0/+3
Fixes #287 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-08-12aio: fix edge cases with error on blocking readSteve Bennett1-10/+3
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-06aio: fix autocomplete for socketSteve Bennett1-3/+8
The checks for -ipv6, -async broke 'socket -commands' Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04aio: support accept ?-noclose?Steve Bennett1-3/+11
And also fix a minor bug that if unable to format the socket address the file descriptor would be left open. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04aio: add -noclose flag to socket and openSteve Bennett1-25/+42
socket ?-noclose? ... open filename ?-noclose? ... Normally Jim will set O_CLOEXEC on all files and sockets that are opened however sometimes it is desirable to keep file descriptors open for child processes. The -noclose flags does this (on supported platforms). Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04aio: change to use unix io, not stdioSteve Bennett1-0/+3
This changes especially makes buffered I/O work with non-blocking channels. - separate read and write buffering - support for timeout on blocking read - read/write on same channel in event loop with buffering - read buffer is the same across read, gets, copyto - autoflush non-blocking writes via event loop - copyto can now copy to any filehandle-like command - add some copyto tests Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04aio: close should still close AIO_KEEPOPEN channelsSteve Bennett1-1/+4
AIO_KEEPOPEN won't close a channel (such as stdin, stdout) when the command is deleted/replaced, but an explicit close will still close the channel. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04aio: change to use unix io, not stdioSteve Bennett1-398/+685
This changes especially makes buffered I/O work with non-blocking channels. - separate read and write buffering - support for timeout on blocking read - read/write on same channel in event loop with buffering - read buffer is the same across read, gets, copyto - autoflush non-blocking writes via event loop - copyto can now copy to any filehandle-like command - add some copyto tests Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-03-20build: define _GNU_SOURCE only on the command lineSteve Bennett1-3/+0
Not in source files See https://ariadne.space/2021/12/21/stop-defining-feature-test-macros-in-your-code/ Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-03Convert some errant malloc/free to Jim_Alloc()/Jim_Free()Steve Bennett1-2/+2
Go through the Jim versions where it makes sense so we can add debugging or other features as required. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-01-31aio copyto: improve performance for large copiesSteve Bennett1-6/+18
Rather than continuing to use a small buffer for large copies, if the size exceeds a certain threshold (currently 16kB) switch to a larger, allocated buffer (currently 64kB). This should speed up large copies without penalising small copies. Note that these are simply heuristics and may not be appropriate on all systems. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-08-21aio: socket filename should provide something useful if possibleSteve Bennett1-2/+7
For socket types that take an address, it would be useful to return that with 'filename'. If not, we can continue to return the socket type.
2022-08-21aio: openpty: return filenameSteve Bennett1-2/+8
$handle filename will now return the replica filename Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-08-20socket: add support for -asyncSteve Bennett1-20/+51
Very similar to Tcl except that read/write can't be done until writable indicates the socket is connected. Signed-off-by: Steve Bennett <steveb@workware.net.au> Documentation fixes - Co-authored-by: Adrian Ho <the.gromgit@gmail.com>
2022-04-14aio: TIP 603 - Implement stat of an open file handleSteve Bennett1-0/+24
Although the interface is different ('$handle stat' vs 'chan configure -stat') the behaviour is the same. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-04-05aio: read: better handling of -pendingSteve Bennett1-2/+6
Once we determine the number of pending bytes to read, there is no need to read one at a time. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-04-05aio: ssl: Fix eof detection with openssl3Steve Bennett1-3/+6
Detection of eof takes precedence over detection of error. Fixes #207 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-02-23aio: gets: Improve behaviour for non-blocking streamsSteve Bennett1-17/+37
Previously calling gets on a non-blocking stream could easily result in a partial line. Now if a partial line is read, return zero/empty to indicate that nothing is available while storing the partial line. The next call to gets (typically within a readable script) will continue appending to the previous partial line until a complete line can be returned. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-07-15aio: Fix the 'lock' subcommandSteve Bennett1-2/+2
The name of the subcommand was inadvertently "lock ?-wait?" rather than "lock" Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-03-07aio: pass socktype to getaddrinfo()prpr19xx1-8/+10
Some old systems are not happy with a numeric service and no socktype. Fixes #196 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-02-27aio: mingw doesn't have O_NOCTTYSteve Bennett1-0/+4
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-02-27aio: open: support for POSIX open flagsSteve Bennett1-3/+46
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-02-20aio: rework internals of openSteve Bennett1-25/+27
In preparation for support of posix mode flags to open Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-15eventloop: Add convenience functions for adding script file handlersSteve Bennett1-38/+11
Add Jim_CreateScriptFileHandler() to create a standard script filehandler event that evaluates the given script with Jim_EvalObjBackground() when the event occurs. Also add Jim_FindFileHandler() to find a registered event handler. Simplify aio by using these. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-07-24aio: ssl: connection close isn't an errorSteve Bennett1-1/+5
A return code of SSL_ERROR_ZERO_RETURN means the connection was closed. It isn't an error. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-05core: command (proc) names may now contained embedded nullsSteve Bennett1-1/+1
The hash table used to store commands now uses Jim_Obj keys rather than allocated char *, so embedded nulls are supported. This means that some API function such as Jim_RenameCommand() now take Jim_Obj * rather than const char *, however Jim_CreateCommand() is retained with const char * for convenience and the new Jim_CreateCommandObj() is added. This is generally a performance win as the existing Jim_Obj can be used as the key. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06aio: Add socket ptySteve Bennett1-1/+36
Allows a psuedo-tty pair to be created. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06aio: ssl: Allow SNI to be specifiedSteve Bennett1-10/+31
For some SSL connections it is necessary to set the Server Name Indication in the connection in order to receive the correct certificate. Allow this as part of the client ssl call with: $sock ssl -sni $servername Also for -server mode, allow the certificate and private key to be stored in a single file and only be specified once. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06aio: Fix eventloop and eof for ssl connectionsSteve Bennett1-33/+101
We can't use feof() and 'buffering none' on ssl connections. Instead we have to get eof from the ssl layer, and provide special handling for buffering in the eventloop. For eof, add ssl_eof() and detect SSL_read() results that indicate eof to set AIO_EOF in flags. For buffering, add 'read -pending' that will read, and then immediately read any buffered data so that the 'readable' event will trigger next time. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04tests: Fixes to recent tests for windowsSteve Bennett1-1/+1
Mostly just avoiding running certain tests, but also: - rename() won't overwrite an existing file on Windows - ensure that eof returns 0 or 1 - in aio.test, create and read the file in binary mode Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04aio: Improve ipv6 error messageSteve Bennett1-1/+1
To show both the host and port Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04aio: remove leftover debuggingSteve Bennett1-1/+0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-11-12aio: tty: allow setting echoSteve Bennett1-1/+1
set-only e.g. to disable echo on stdin: stdin tty echo 0 This allows disabling echo while otherwise keeping cooked mode. Setting input to cooked or raw will overwrite this setting Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-11-09aio: make some data constSteve Bennett1-3/+3
Move some remaining data to the read-only segment Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-10-30aio: need SO_REUSEADDR before bind()Steve Bennett1-3/+3
Commit fe8bab1cc313d0049bbb839589c68059807518c8 accidentally moved the SO_REUSEADDR after bind() where it does no good. Move it back to before bind() Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-08-14aio: Significantly improve the speed of copytoSteve Bennett1-4/+10
Copying 1 byte at a time can be very slow for large transfers. Use a 256 byte buffer instead. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-08-14aio: minor code improvementSteve Bennett1-2/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-07-31aio: Add support for lock -waitSteve Bennett1-4/+12
Sometimes it is useful to wait for a lock to become available. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2019-07-01aio: Add dgram unix socket supportSteve Bennett1-275/+402
Also add support for sockname and peername And remove unix domain sockets when the socket is closed And generally clean up the socket support Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-11-24aio: Prefer TLS_method() over TLSv1_2_method()Steve Bennett1-1/+5
To avoid a deprecation warning Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-11-23aio: Don't use FD_CLOEXEC with JIM_ANSICSteve Bennett1-3/+3
Bootstrap jimsh sets JIM_ANSIC but FD_CLOEXEC is enabled. This causes FD_CLOEXEC to be set on fd 0 (stdin), thus closing the default fd 0 in the child process during exec. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-09-04Tidy some signed/unsigned comparisonsSteve Bennett1-1/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-08aio: Fall back to stdio error if no ssl errorSteve Bennett1-3/+3
Conditions such as ECONNRESET may result in a failed ssl connection with no ssl error, so return the stdio error in this case rather than just "unknown SSL error" Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-08aio: Always set error message on I/O errorSteve Bennett1-5/+10
Some operations that failed (such as read) would leave an empty error result. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-10-21aio: No need to create a new channel for sslSteve Bennett1-20/+11
Just "promote" the current channel to ssl Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-10-17signal, exec, wait, pid: improvements, especially to execSteve Bennett1-89/+81
- fix popen [open "|pipeline ..."] to return meaningful status in close (but note that stderr is not captured) - popen pipelines can now be used as the target of exec redirection - overally improvements to exec on windows. Now crt file descriptors are used throughout - add support for [pid], [wait] and popen on windows - os.wait is now wait, and integrates with [exec ... &] to be able to wait for running background tasks - [socket pipe] is now also [pipe] and is supported on windows - [file tempfile] is supported on windows - move duplicated code between jim-aio.c and jim-exec.c to jimiocompat.c - Fix [exec] on windows to match unix semantics wrt sharing the parent stream unless redirected rather than using /dev/null - On windows redirect to or from /dev/null is automatically converted to NUL: - If signal support is disabled, implement a minimal Jim_SignalId() for exec and wait - aio now supports getfd, to return the underlying file descriptor. This is used by exec to support redirection, and allows popen channels to support exec redirection. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-10-16aio tempname: Fix a crash when the template is invalidSteve Bennett1-2/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-15aio: Add support for many socket optionsSteve Bennett1-15/+100
Add aio sockopt to get and set various socket options via setsockopt()/getsockopt() And remove 'aio tcp_nodelay' in favour of 'aio sockopt tcp_nodelay' Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-20aio: Only allow TCP_NODELAY if sockets are supportedSteve Bennett1-2/+2
Sockets need extra work on Windows, so not supported there yet. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-20aio: Add support for TCP_NODELAYSteve Bennett1-0/+26
Enable or disable Nagle's algorigthm Signed-off-by: Steve Bennett <steveb@workware.net.au>