Package smsqmulator

Class IPSocket

java.lang.Object
smsqmulator.IPSocket

public class IPSocket extends Object
A socket which may be of different types. This class tries to mask the difference between a java.net.Socket and a java.net.ServerSocket. For TCP: In java, A socket is either a server socket that is listening for (and accepting) connections, or a client socket that tries to get a. connection to the server . The problem is that a 'C' socket may be used indifferently (within reason) as client or server socket. What it will be is determined, more or less, by the "connect" and "listen/accept" calls : the first sets the socket to be a client socket, the second to be a server socket. So here I sometimes have to defer creating the actual real socket until connect or listen calls are made. Moreover, the listen function as such doesn't exist in java. However, when that call is issued, I know that the corresponding socket should be a server socket. *
  • Field Details

  • Constructor Details

    • IPSocket

      public IPSocket(MC68000Cpu cpu, IPSocket[] sockets)
      Create a socket.
      Parameters:
      cpu - the cpu used.
      sockets - array with all open sockets.
  • Method Details

    • close

      public void close()
      Close the socket and all associated channels. Ignore all errors.
    • getConnectionStatus

      public IPSocket.CONN_STATUS getConnectionStatus()
      Gets the connection status.
      Returns:
      the connection status, one of IPSocket.CONN_STATUS.
    • getSocketType

      public int getSocketType()
      Get the socket type.
      Returns:
      the SOCKET_TYPE {SCK,TCP,UDP,NONE}
    • getSocket

      public Socket getSocket()
      Get the TCP client socket.
      Returns:
      the TCP client socket
    • getServerSocket

      public ServerSocket getServerSocket()
      Get the TCP server socket.
      Returns:
      the TCP server socket
    • getLastError

      public int getLastError()
      Gets the last error from this socket.
      Returns:
      the last error encountered by the socket when send/receiving,connecting/listening.
    • setLastError

      public void setLastError(int err)
      Sets the last error for the socket.
      Parameters:
      err - the last error encountered by the socket when send/receiving,connecting/listening.
    • bind

      public int bind(MC68000Cpu cpu)
      Binds a socket. This means the port and host addresses are set.
      Parameters:
      cpu - the smsqmulator.cpu.MC68000Cpu object.
      Returns:
      0 or SMSQ/E error code.
    • connect

      public int connect(MC68000Cpu cpu)
      Connects an existing socket. This means that the socket will be a client socket (TCP).
      Parameters:
      cpu - the smsqmulator.cpu.MC68000Cpu (A1 points to a sockaddr structure)
      Returns:
      SMSQ/E error code or 0
    • listen

      public int listen(MC68000Cpu cpu)
      Makes an existing socket a "listening" one. . This means that the socket will be a server socket (TCP). This socket is actually created here.
      Parameters:
      cpu - (a1 points to a sockaddr structure)
      Returns:
      error code or 0
    • send

      public int send(MC68000Cpu cpu, int size)
      Send bytes out over the port. Note this is sent over an unprotected, naked, unbuffered socket.
      Parameters:
      cpu - the cpu to get data to be sent from, it lies at (A1), ndr of bytes to be sent in D2.L.
      size - nbr of bytes to send
      Returns:
      nbr of bytes sent or negative SMSQ/E error code.
    • sendTo

      public int sendTo(MC68000Cpu cpu, int size)
      Sendto - only allowed for TCP where it is the same as "send".
      Parameters:
      cpu - the cpu used.
      size - size of data to be set, in bytes.
      Returns:
      SMSQ/E type error code (0 if no error).
    • send1Byte

      public int send1Byte(MC68000Cpu cpu, int byt)
      Send one byte out over the socket.
      Parameters:
      cpu - the cpu used
      byt - the byte to send
      Returns:
      0 or SMSQ/E error.
    • receive

      public int receive(MC68000Cpu cpu, int size, boolean checkD1, byte[] byt)
      Receive bytes from the port and copy them to (A1), updating A1. on entry, D1 MAY hold a flag, which COULD be as follows 0x0 // no flag MSG_OOB 0x1 // process out-of-band data MSG_PEEK 0x2 /* peek at incoming message MSG_DONTROUTE 0x4 /* send without using routing tables MSG_EOR 0x8 /* data completes record MSG_TRUNC 0x10 /* data discarded before delivery MSG_CTRUNC 0x20 /* control data lost before delivery MSG_WAITALL 0x40 /* wait for full request or error for the time being, only cases 0 and 2 are honoured.
      Parameters:
      cpu - the CPU used.
      size - nbr of bytes to read
      checkD1 - if true, should check D1 for flags, else ignore D1.
      byt - byt array into which to receive, if null, a temporary one will be used here.
      Returns:
      SMSQ/E negative error code or the number of bytes I got
    • receive1Byte

      public int receive1Byte(MC68000Cpu cpu, byte[] byt, int timeout)
      Receive one byte from the port and return it - for the time being, only cases 0 and 2 are honoured.
      Parameters:
      cpu - the CPU used.
      byt - a byte array with ONE ELEMENT ONLY into which the byte goes, may not be null.
      timeout - socket timeout, millisecs.
      Returns:
      SMSQ/E error code or 0 if all ok.
    • getRemote

      public int getRemote(MC68000Cpu cpu)
      Get info on the remote host, put it at (A1). at A1 lies : family, port, ipv4 address. On return D1.L = length of answer. On entry, D2.L = length of buffer
      Parameters:
      cpu - the cpu used
      Returns:
      SMSQ/E error code (0 if no error).
    • getRemoteChanName

      public String getRemoteChanName()
      Get the name of the remote channel.
      Returns:
      the name of the remote channel or empty string if not connected.
    • getName

      public String getName()
      Gets the name of the current socket, including address, port and connection status.
      Returns:
      the full name, e.g "TCP_127.0.0.1:123 (l)" means a TCP connection to localhost, "listening" on port 123.