Skip to content

Commit

Permalink
aio: add 'sync' subcommand
Browse files Browse the repository at this point in the history
If the underlying platform supports fsync(), $handle sync
invokes fsync() on the stream file descriptor.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information
msteveb committed Mar 19, 2015
1 parent fffae89 commit c73f5c5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion auto.def
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ cc-check-functions ualarm lstat fork vfork system select execvpe
cc-check-functions backtrace geteuid mkstemp realpath strptime isatty
cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
cc-check-functions shutdown socketpair isinf isnan link symlink
cc-check-functions shutdown socketpair isinf isnan link symlink fsync

if {[cc-check-functions sysinfo]} {
cc-with {-includes sys/sysinfo.h} {
Expand Down
20 changes: 20 additions & 0 deletions jim-aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,17 @@ static int aio_cmd_ndelay(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
#endif

#ifdef HAVE_FSYNC
static int aio_cmd_sync(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);

fflush(af->fp);
fsync(af->fd);
return JIM_OK;
}
#endif

static int aio_cmd_buffering(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
Expand Down Expand Up @@ -994,6 +1005,15 @@ static const jim_subcmd_type aio_command_table[] = {
1,
/* Description: Set O_NDELAY (if arg). Returns current/new setting. */
},
#endif
#ifdef HAVE_FSYNC
{ "sync",
NULL,
aio_cmd_sync,
0,
0,
/* Description: Flush and fsync() the stream */
},
#endif
{ "buffering",
"none|line|full",
Expand Down
36 changes: 22 additions & 14 deletions jim_tcl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Jim Tcl(n)

NAME
----
Jim Tcl v0.76 - reference manual for the Jim Tcl scripting language
Jim Tcl v0.76+ - reference manual for the Jim Tcl scripting language

SYNOPSIS
--------
Expand Down Expand Up @@ -51,6 +51,10 @@ Some notable differences with Tcl 8.5/8.6 are:

RECENT CHANGES
--------------
Changes between 0.76 and 0.77
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Add support for `aio sync`

Changes between 0.75 and 0.76
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Add support for `file link`
Expand Down Expand Up @@ -2262,7 +2266,7 @@ abbreviation for +'option'+ is acceptable. The valid options are:
If it can't be deleted, an error is generated. Non-empty directories will not be deleted
unless the +-force+ options is given. In this case no errors will be generated, even
if the file/directory can't be deleted. Use +'--'+ if there is any possibility of
the first name being +'-force'+.
the first name being +'-force'+.

+*file dirname* 'name'+::
Return all of the characters in +'name'+ up to but not including
Expand Down Expand Up @@ -2298,8 +2302,8 @@ abbreviation for +'option'+ is acceptable. The valid options are:

+*file link* ?*-hard|-symbolic*? 'newname target'+::
Creates a hard link (default) or symbolic link from +'newname'+ to +'target'+.
Note that the sense of this command is the opposite of `file rename` and `file copy`
and also of `ln`, but this is compatible with Tcl.
Note that the sense of this command is the opposite of `file rename` and `file copy`
and also of `ln`, but this is compatible with Tcl.
An error is returned if +'target'+ doesn't exist or +'newname'+ already exists.

+*file lstat* 'name varName'+::
Expand Down Expand Up @@ -2347,8 +2351,8 @@ abbreviation for +'option'+ is acceptable. The valid options are:

+*file rename* ?*-force*? 'oldname' 'newname'+::
Renames the file from the old name to the new name.
If +'newname'+ already exists, an error is returned unless +'-force'+ is
specified.
If +'newname'+ already exists, an error is returned unless +'-force'+ is
specified.

+*file rootname* 'name'+::
Return all of the characters in +'name'+ up to but not including
Expand All @@ -2362,16 +2366,16 @@ abbreviation for +'option'+ is acceptable. The valid options are:

+*file stat* 'name ?varName?'+::
Invoke the 'stat' kernel call on +'name'+, and return the result
as a dictionary with the following keys: 'atime',
as a dictionary with the following keys: 'atime',
'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
'nlink', 'size', 'type', 'uid'.
Each element except 'type' is a decimal string with the value of
the corresponding field from the 'stat' return structure; see the
manual entry for 'stat' for details on the meanings of the values.
The 'type' element gives the type of the file in the same form
returned by the command `file type`.
If +'varName'+ is specified, it is taken to be the name of an array
variable and the values are also stored into the array.
If +'varName'+ is specified, it is taken to be the name of an array
variable and the values are also stored into the array.

+*file tail* 'name'+::
Return all of the characters in +'name'+ after the last slash.
Expand Down Expand Up @@ -2750,8 +2754,8 @@ The legal +'option'+'s (which may be abbreviated) are:
With a single argument, returns the original source location of the given script as a list of
+{filename linenumber}+. If the source location can't be determined, the
list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy
of +'script'+ with the associate source information. This can be useful to produce
useful messages from `eval`, etc. if the original source information may be lost.
of +'script'+ with the associate source information. This can be useful to produce
useful messages from `eval`, etc. if the original source information may be lost.

+*info stacktrace*+::
After an error is caught with `catch`, returns the stack trace as a list
Expand Down Expand Up @@ -4472,7 +4476,7 @@ aio

+$handle *close* ?r(ead)|w(rite)?+::
Closes the stream.
The two-argument form is a "half-close" on a socket. See the +shutdown(2)+ man page.
The two-argument form is a "half-close" on a socket. See the +shutdown(2)+ man page.

+$handle *copyto* 'tofd ?size?'+::
Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
Expand Down Expand Up @@ -4521,6 +4525,10 @@ aio
ways for other handle types.
Returns the number of bytes written.

+$handle *sync*+::
Flush the stream, then fsync(2) to commit any changes to storage.
Only available on platforms that support fsync(2).

+$handle *tell*+::
Returns the current seek position

Expand Down Expand Up @@ -4603,8 +4611,8 @@ to prevent infinite errors. (A time event handler is always removed after execut

+*bgerror* 'msg'+::
Called when an event handler script generates an error. Note that the normal command resolution
rules are used for bgerror. First the name is resolved in the current namespace, then in the
global scope.
rules are used for bgerror. First the name is resolved in the current namespace, then in the
global scope.

socket
~~~~~~
Expand Down

0 comments on commit c73f5c5

Please sign in to comment.