|
Class: FileDescriptorHandle (private in UnixOperatingSystem
This class is only visible from within
UnixOperatingSystem.
Object
|
+--UnixOperatingSystem::FileDescriptorHandle
- Package:
- stx:libbasic
- Category:
- OS-Unix
- Owner:
- UnixOperatingSystem
change & update
-
update: aspect with: argument from: anObject
-
one of our registered handles has been collected
initialization
-
initialize
-
self initialize
instance creation
-
for: aFileDescriptor
-
create an instance of myself for a given fileDescriptor
error handling
-
error: anErrorSymbolOrErrno
-
got an error; arg is either a symbol specifying a primitive error
or the error number as returned by the OperatingSystem
file access
-
close
-
close the descriptor
initialization
-
for: aFileDescriptor
-
create a file for a handle
input/output
-
readBytes: count into: aByteBuffer startingAt: firstIndex
-
read count bytes into a byte-buffer;
Return the number of bytes read.
The read is non-blocking. If the operation would block
either an incomplete count or nil will be returned.
An exception is raised on any other error
Usage example(s):
|h buff n|
h := OperatingSystem openFileForRead:'/etc/hosts'.
buff := ByteArray new:1000. buff inspect.
n := h readBytes:1000 into:buff startingAt:1.
Transcript show:n; space; showCR:buff asString.
|
Usage example(s):
|h buff n|
h := OperatingSystem openFileForRead:'/dev/cua0'.
buff := ByteArray new:1000. buff inspect.
n := h readBytes:1000 into:buff startingAt:1.
Transcript show:n printString; space; showCR:buff asString.
|
-
writeBytes: count from: aByteBuffer startingAt: firstIndex
-
write count bytes from a byte-buffer;
Return the number of bytes written (negative on error)
Usage example(s):
|h buff n|
h := OperatingSystem createFileForReadWrite:'/tmp/xx'.
buff := '12345678901234567890'.
n := h writeBytes:10 from:buff startingAt:1.
|
Usage example(s):
|h buff n|
h := OperatingSystem createFileForReadWrite:'/dev/cua0'.
buff := '12345678901234567890'.
n := h writeBytes:10 from:buff startingAt:1.
|
misc functions
-
nextError
-
retrieve the pending error from the current fileDescriptor
and raise an error exception.
This should be only called, when an error is pending.
Otherwise a byte may be lost
-
seekTo: newPosition from: whence
-
seek to newPosition
whence is one of: #begin #current #end.
Return the new position.
Usage example(s):
|h buff n|
h := OperatingSystem openFileForRead:'/etc/hosts'.
h seekTo:10 from:#begin.
buff := ByteArray new:1000. buff inspect.
n := h readBytes:1000 into:buff startingAt:1.
Transcript show:n; space; showCR:buff asString.
|
-
selectWithTimeOut: millis
-
wait for aFileDesriptor to become ready; timeout after t milliseconds.
Return true, if i/o ok, false if timed-out or interrupted.
With 0 as timeout argument, this can be used to check for availability (poll)
of read-data.
-
setBlocking: aBoolean
-
set/clear the blocking attribute - if set (which is the default)
a read on the fileDescriptor will block until data is available.
If cleared, a read operation will immediately return with a value of
nil if no data is available.
private-accessing
-
fileDescriptor
-
return the (integer) fileDescriptor
-
setFileDescriptor: anInteger
-
queries
-
canReadWithoutBlocking
-
return true, if data is available on a filedescriptor
(i.e. read is possible without blocking).
This depends on a working select or FIONREAD to be provided by the OS.
Usage example(s):
|h n|
h := OperatingSystem openFileForRead:'/etc/hosts'.
n := h canReadWithoutBlocking.
h close.
n
|
Usage example(s):
|h n|
h := OperatingSystem openFileForRead:'/dev/ttyS0'.
n := h canReadWithoutBlocking.
h close.
n
|
-
canWriteWithoutBlocking
-
return true, if filedescriptor can be written without blocking
-
isValid
-
answer true, if the handle is valid, i.e. connected to
a file or some other OS object
-
numAvailableForRead
-
return the number of bytes available for reading, without blocking.
Usage example(s):
|h n|
h := OperatingSystem openFileForRead:'/etc/hosts'.
n := h numAvailableForRead.
h close.
n
|
registering
-
register
-
register myself as an open file
releasing
-
invalidate
-
a file handle has become invalid
waiting
-
readWaitWithTimeoutMs: timeout
-
suspend the current process, until the receiver
becomes ready for reading or a timeout (in milliseconds) expired.
If data is already available, return immediate.
Return true if a timeout occurred (i.e. false, if data is available).
The other threads are not affected by the wait.
-
writeWaitWithTimeoutMs: timeout
-
suspend the current process, until the receiver
becomes ready for writing or a timeout (in seconds) expired.
Return true if a timeout occurred (i.e. false, if data is available).
Return immediate if the receiver is already ready.
The other threads are not affected by the wait.
|