org.jawk.ext
Class SocketExtension

java.lang.Object
  extended by org.jawk.ext.AbstractExtension
      extended by org.jawk.ext.SocketExtension
All Implemented Interfaces:
JawkExtension

public class SocketExtension
extends AbstractExtension

Enable Socket processing in Jawk.

To use:

 ## example echo server using CServerSocket (character-based)
 BEGIN {
        css = CServerSocket(7777);
 }
 $0 = SocketAcceptBlock(css,
        SocketInputBlock(handles,
        SocketCloseBlock(css, handles \
        )));
 $1 == "SocketAccept" {
        handles[SocketAccept($2)] = 1
 }
 $1 == "SocketClose" {
        SocketClose($2)
        delete handles[$2]
 }
 $1 == "SocketInput" {
        input = SocketRead($2)
        SocketWrite($2, input); ## do the echo
 }
 

The extension functions are as follows:


Field Summary
 
Fields inherited from class org.jawk.ext.AbstractExtension
jrt, vm
 
Constructor Summary
SocketExtension()
           
 
Method Summary
 java.lang.String[] extensionKeywords()
          All the extended keywords supported by this extension.
 java.lang.String getExtensionName()
          The name of the extension package.
 void init(VariableManager vm, JRT jrt)
          Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.
 java.lang.Object invoke(java.lang.String method_name, java.lang.Object[] args)
          Invoke extension as a method.
 
Methods inherited from class org.jawk.ext.AbstractExtension
checkNumArgs, getAssocArrayParameterPositions, toAwkString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketExtension

public SocketExtension()
Method Detail

init

public final void init(VariableManager vm,
                       JRT jrt)
Description copied from interface: JawkExtension
Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.

It is guaranteed init() is called before invoke() is called.

Specified by:
init in interface JawkExtension
Overrides:
init in class AbstractExtension

getExtensionName

public final java.lang.String getExtensionName()
Description copied from interface: JawkExtension
The name of the extension package.


extensionKeywords

public final java.lang.String[] extensionKeywords()
Description copied from interface: JawkExtension
All the extended keywords supported by this extension.

Note: Jawk will throw a runtime exception if the keyword collides with any other keyword in the system, extension or otherwise.


invoke

public final java.lang.Object invoke(java.lang.String method_name,
                                     java.lang.Object[] args)
Description copied from interface: JawkExtension
Invoke extension as a method.

Parameters:
method_name - The extension keyword.
args - Arguments to the extension.
Returns:
The return value (result) of the extension.