eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'UnixOperatingSystem::FileDescriptorHandle':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: FileDescriptorHandle (private in UnixOperatingSystem

This class is only visible from within UnixOperatingSystem.

Inheritance:

   Object
   |
   +--UnixOperatingSystem::FileDescriptorHandle

Package:
stx:libbasic
Category:
OS-Unix
Owner:
UnixOperatingSystem

Class protocol:

change & update
o  update: aspect with: argument from: anObject
one of our registered handles has been collected

initialization
o  initialize
self initialize

instance creation
o  for: aFileDescriptor
create an instance of myself for a given fileDescriptor


Instance protocol:

error handling
o  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
o  close
close the descriptor

initialization
o  for: aFileDescriptor
create a file for a handle

input/output
o  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.

o  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
o  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

o  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.

o  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.

o  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
o  fileDescriptor
return the (integer) fileDescriptor

o  setFileDescriptor: anInteger

queries
o  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

o  canWriteWithoutBlocking
return true, if filedescriptor can be written without blocking

o  isValid
answer true, if the handle is valid, i.e. connected to
a file or some other OS object

o  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
o  register
register myself as an open file

releasing
o  invalidate
a file handle has become invalid

waiting
o  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.

o  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.



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:35:02 GMT