indexing
	description: "A datagram socket."
	legal: "See notice at end of class."
	status: "See notice at end of class."
	date: "$Date: 2007-01-26 09:09:11 -0800 (Fri, 26 Jan 2007) $"
	revision: "$Revision: 66294 $"

deferred class interface
	DATAGRAM_SOCKET


feature -- Initialization

	create_from_descriptor (fd: INTEGER_32)
			-- Create socket from descriptor `fd'.
			-- (from SOCKET)
		ensure -- from SOCKET
			family_valid: family = address.family
			opened_all: is_open_write and is_open_read
	
feature -- Access

	generating_type: STRING_8
			-- Name of current object's generating type
			-- (type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generating_type_not_void: Result /= Void
			generating_type_not_empty: not Result.is_empty

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty

	retrieved: ANY
			-- Retrieved object structure
			-- To access resulting object under correct type,
			-- use assignment attempt.
			-- Will raise an exception (code Retrieve_exception)
			-- if content is not a stored Eiffel structure.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
			support_storable: support_storable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read
			support_storable: support_storable
		ensure -- from IO_MEDIUM
			result_exists: Result /= Void
	
feature -- Comparison

	frozen deep_equal (some: ?ANY; other: like arg #1): BOOLEAN
			-- Are `some' and `other' either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		ensure -- from ANY
			shallow_implies_deep: standard_equal (some, other) implies Result
			both_or_none_void: (some = Void) implies (Result = (other = Void))
			same_type: (Result and (some /= Void)) implies (other /= Void and then some.same_type (other))
			symmetric: Result implies deep_equal (other, some)

	frozen equal (some: ?ANY; other: like arg #1): BOOLEAN
			-- Are `some' and `other' either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		ensure -- from ANY
			definition: Result = (some = Void and other = Void) or else ((some /= Void and other /= Void) and then some.is_equal (other))

	frozen is_deep_equal (other: DATAGRAM_SOCKET): BOOLEAN
			-- Are `Current' and `other' attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)

	is_equal (other: DATAGRAM_SOCKET): BOOLEAN
			-- Is `other' attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			symmetric: Result implies other.is_equal (Current)
			consistent: standard_is_equal (other) implies Result

	frozen standard_equal (some: ?ANY; other: like arg #1): BOOLEAN
			-- Are `some' and `other' either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		ensure -- from ANY
			definition: Result = (some = Void and other = Void) or else ((some /= Void and other /= Void) and then some.standard_is_equal (other))

	frozen standard_is_equal (other: DATAGRAM_SOCKET): BOOLEAN
			-- Is `other' attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
	
feature -- Status report

	address_in_use: BOOLEAN
			-- Address is in use by another socket.
			-- (from SOCKET_RESOURCES)

	address_not_readable: BOOLEAN
			-- Unreadable address
			-- (from SOCKET_RESOURCES)

	already_bound: BOOLEAN
			-- Socket has already been bound.
			-- (from SOCKET_RESOURCES)

	bad_socket_handle: BOOLEAN
			-- Socket descriptor is bad.
			-- (from SOCKET_RESOURCES)

	bound: BOOLEAN
			-- Has socket been bound?

	bytes_read: INTEGER_32
			-- Last number of bytes read by read_to_managed_pointer.
			-- (from IO_MEDIUM)

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of `other' (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void

	connect_in_progress: BOOLEAN
			-- Call to connect returned on a non-blocking socket.
			-- (from SOCKET_RESOURCES)

	connection_refused: BOOLEAN
			-- Connection is refused (possibly due to security).
			-- (from SOCKET_RESOURCES)

	dtable_full: BOOLEAN
			-- Descriptor table is full
			-- (from SOCKET_RESOURCES)

	error: STRING_8
			-- Output a related error message.
			-- (from SOCKET_RESOURCES)

	error_number: INTEGER_32
			-- Returned error number
			-- (from SOCKET_RESOURCES)

	expired_socket: BOOLEAN
			-- Socket connection has expired.
			-- (from SOCKET_RESOURCES)

	invalid_address: BOOLEAN
			-- Address is not valid.
			-- (from SOCKET_RESOURCES)

	invalid_socket_handle: BOOLEAN
			-- Socket descriptor is not valid.
			-- (from SOCKET_RESOURCES)

	is_plain_text: BOOLEAN
			-- Is file reserved for text (character sequences)?
			-- (from IO_MEDIUM)

	is_valid_peer_address (addr: SOCKET_ADDRESS): BOOLEAN
			-- Is `addr' a valid peer address?
			-- (from SOCKET)
		require -- from SOCKET
			address_exists: addr /= Void

	last_character: CHARACTER_8
			-- Last character read by read_character
			-- (from IO_MEDIUM)

	last_double: REAL_64
			-- Last double read by read_double
			-- (from IO_MEDIUM)

	last_integer: INTEGER_32
			-- Last integer read by read_integer
			-- (from IO_MEDIUM)

	last_integer_16: INTEGER_16
			-- Last 16-bit integer read by read_integer_16
			-- (from IO_MEDIUM)

	last_integer_32: INTEGER_32
			-- Synonymy of last_integer
			-- (from IO_MEDIUM)

	last_integer_64: INTEGER_64
			-- Last 64-bit integer read by read_integer_64
			-- (from IO_MEDIUM)

	last_integer_8: INTEGER_8
			-- Last 8-bit integer read by read_integer_8
			-- (from IO_MEDIUM)

	last_natural: NATURAL_32
			-- Last 32-bit natural read by read_natural
			-- (from IO_MEDIUM)

	last_natural_16: NATURAL_16
			-- Last 16-bit natural read by read_natural_16
			-- (from IO_MEDIUM)

	last_natural_32: NATURAL_32
			-- Synonymy of last_natural
			-- (from IO_MEDIUM)

	last_natural_64: NATURAL_64
			-- Last 64-bit natural read by read_natural_64
			-- (from IO_MEDIUM)

	last_natural_8: NATURAL_8
			-- Last 8-bit natural read by read_natural_8
			-- (from IO_MEDIUM)

	last_real: REAL_32
			-- Last real read by read_real
			-- (from IO_MEDIUM)

	last_string: ?STRING_8
			-- Last string read
			-- (from IO_MEDIUM)

	network: BOOLEAN
			-- Socket failed due to network problems.
			-- (from SOCKET_RESOURCES)

	no_buffers: BOOLEAN
			-- No more buffers available
			-- (from SOCKET_RESOURCES)

	no_permission: BOOLEAN
			-- No permission is given to user for this socket.
			-- (from SOCKET_RESOURCES)

	not_connected: BOOLEAN
			-- Socket is not connect.
			-- (from SOCKET_RESOURCES)

	protected_address: BOOLEAN
			-- No access to this address is allowed.
			-- (from SOCKET_RESOURCES)

	protocol_not_supported: BOOLEAN
			-- Protocol is not supported on this platform.
			-- (from SOCKET_RESOURCES)

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of `other'?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))

	socket_family_not_supported: BOOLEAN
			-- Requested family is not supported.
			-- (from SOCKET_RESOURCES)

	socket_in_use: BOOLEAN
			-- Socket is already in use.
			-- (from SOCKET_RESOURCES)

	socket_ok: BOOLEAN
			-- No error
			-- (from SOCKET_RESOURCES)

	socket_would_block: BOOLEAN
			-- Call to read, write, etc would have blocked.
			-- (from SOCKET_RESOURCES)

	support_storable: BOOLEAN
			-- Can medium be used to store an Eiffel structure?
			-- (from SOCKET)

	zero_option: BOOLEAN
			-- No options provided
			-- (from SOCKET_RESOURCES)
	
feature -- Element change

	basic_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from `object'.
			-- Retrievable within current system only.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: support_storable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_write: is_open_write
			support_storable: support_storable

	general_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from `object'.
			-- Retrievable from other systems for same platform
			-- (machine architecture).
			-- (from SOCKET)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: support_storable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_write: is_open_write
			support_storable: support_storable

	independent_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from `object'.
			-- Retrievable from other systems for the same or other
			-- platform (machine architecture).
			-- (from SOCKET)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: support_storable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_write: is_open_write
			support_storable: support_storable
	
feature -- Removal

	dispose
			-- Ensure this medium is closed when garbage collected.
			-- (from IO_MEDIUM)
	
feature -- Duplication

	copy (other: DATAGRAM_SOCKET)
			-- Update current object using fields of object attached
			-- to `other', so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		ensure -- from ANY
			is_equal: is_equal (other)

	frozen deep_copy (other: DATAGRAM_SOCKET)
			-- Effect equivalent to that of:
			--		copy (`other' . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)

	frozen deep_twin: DATAGRAM_SOCKET
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)

	frozen standard_copy (other: DATAGRAM_SOCKET)
			-- Copy every field of `other' onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)

	frozen standard_twin: DATAGRAM_SOCKET
			-- New object field-by-field identical to `other'.
			-- Always uses default copying semantics.
			-- (from ANY)
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)

	frozen twin: DATAGRAM_SOCKET
			-- New object equal to `Current'
			-- twin calls copy; to change copying/twining semantics, redefine copy.
			-- (from ANY)
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result.is_equal (Current)
	
feature -- Miscellaneous

	name: STRING_8
			-- Socket name
			-- (from SOCKET)
		require -- from  IO_MEDIUM
			True
		require else -- from SOCKET
			socket_exists: exists
	
feature -- Basic operations

	bind
			-- Bind socket to a local address.

	close
			-- Close socket.

	connect_to_peer (a_peer_address: like address)
			-- Target socket to `a_peer_address'.
		require
			socket_exists: exists

	frozen default: ?DATAGRAM_SOCKET
			-- Default value of object's type
			-- (from ANY)

	frozen default_pointer: POINTER
			-- Default value of type `POINTER'
			-- (Avoid the need to write `p'.default for
			-- some `p' of type `POINTER'.)
			-- (from ANY)

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
	
feature -- Obsolete

	lastchar: CHARACTER_8
			-- Last character read by read_character
			-- (from IO_MEDIUM)

	lastdouble: REAL_64
			-- Last double read by read_double
			-- (from IO_MEDIUM)

	lastint: INTEGER_32
			-- Last integer read by read_integer
			-- (from IO_MEDIUM)

	lastreal: REAL_32
			-- Last real read by read_real
			-- (from IO_MEDIUM)

	laststring: ?STRING_8
			-- Last string read
			-- (from IO_MEDIUM)
	
feature -- Basic commands

	address: SOCKET_ADDRESS
			-- Local address of socket
			-- (from SOCKET)

	socket_bind
			-- Bind socket to local address in address.
			-- (from SOCKET)
		require -- from SOCKET
			socket_exists: exists
			valid_local_address: address /= Void

	cleanup
			-- Cleanup socket.
			-- (from SOCKET)

	socket_close
			-- Close socket for all context.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			medium_is_open: not is_closed
		require else -- from SOCKET
			socket_exists: exists

	close_socket
			-- Close socket for current context.
			-- (from SOCKET)
		require -- from SOCKET
			socket_exists: exists
			is_open: is_open_read or is_open_write
		ensure -- from SOCKET
			is_closed: is_closed
			not_is_open: not is_open_read and not is_open_write

	connect
			-- Connect socket to peer address.
			-- (from SOCKET)
		require -- from SOCKET
			socket_exists: exists
			valid_peer_address: peer_address /= Void

	descriptor: INTEGER_32
			-- Socket descriptor of current socket
			-- (from SOCKET)

	descriptor_available: BOOLEAN
			-- Is descriptor available?
			-- (from SOCKET)

	family: INTEGER_32
			-- Socket family eg. af_inet, af_unix
			-- (from SOCKET)

	is_closed: BOOLEAN
			-- Is socket closed?
			-- (from SOCKET)

	make_socket
			-- Create socket descriptor.
			-- (from SOCKET)
		require -- from SOCKET
			valid_family: family >= 0
			valid_type: type >= 0
			valid_protocol: protocol >= 0

	peer_address: like address
			-- Peer address of socket
			-- (from SOCKET)

	protocol: INTEGER_32
			-- Protocol of the socket. default 0
			-- means for the system to chose the default
			-- protocol for the family chosen. eg. `udp', `tcp'.
			-- (from SOCKET)

	set_address (addr: like address)
			-- Set local address to `addr'.
			-- (from SOCKET)
		require -- from SOCKET
			same_type: addr.family = family
		ensure -- from SOCKET
			address_set: address = addr

	set_peer_address (addr: like address)
			-- Set peer address to `addr'.
			-- (from SOCKET)
		require -- from SOCKET
			address_exists: addr /= Void
			address_valid: is_valid_peer_address (addr)
		ensure -- from SOCKET
			address_set: peer_address = addr

	type: INTEGER_32
			-- Type of socket. eg stream, datagram
			-- (from SOCKET)
	
feature -- Creation

	make
			-- Create a domain typed socket

	make_bound_to_address (a_local_address: like address)
			-- Create a socket bound to its well-known address
			-- `local_address'.

	make_connected_to_peer (a_peer_address: like address)
			-- Create a socket targeted to peer_address.
	
feature -- Externals: flags for send, sendto recv and recvfrom socket calls

	c_msgdontroute: INTEGER_32
			-- Do not route message
			-- (from SOCKET_RESOURCES)

	c_oobmsg: INTEGER_32
			-- Out of bound message 
			-- (from SOCKET_RESOURCES)

	c_peekmsg: INTEGER_32
			-- Peek message
			-- (from SOCKET_RESOURCES)
	
feature -- Input

	last_boolean: BOOLEAN
			-- Last boolean read by read_boolean
			-- (from SOCKET)

	read (size: INTEGER_32): PACKET
			-- Read a packet of data of maximum size `size'.
			-- (from SOCKET)
		require -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_boolean
			-- Read a new boolean.
			-- Maker result available in last_boolean.
			-- Was declared in SOCKET as synonym of readbool.
			-- (from SOCKET)
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_character
			-- Read a new character.
			-- Make result available in last_character.
			-- Was declared in SOCKET as synonym of readchar.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_double
			-- Read a new double.
			-- Make result available in last_double.
			-- Was declared in SOCKET as synonym of readdouble.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_integer
			-- Read a new 32-bit integer.
			-- Make result available in last_integer.
			-- Was declared in SOCKET as synonym of readint and read_integer_32.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_integer_16
			-- Read a new 16-bit integer.
			-- Make result available in last_integer_16.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_integer_32
			-- Read a new 32-bit integer.
			-- Make result available in last_integer.
			-- Was declared in SOCKET as synonym of read_integer and readint.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_integer_64
			-- Read a new 64-bit integer.
			-- Make result available in last_integer_64.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_integer_8
			-- Read a new 8-bit integer.
			-- Make result available in last_integer_8.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_line
			-- Read a line of characters (ended by a new_line).
			-- Was declared in SOCKET as synonym of readline.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void

	read_natural
			-- Read a new 32-bit natural.
			-- Make result available in last_natural.
			-- Was declared in SOCKET as synonym of read_natural_32.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_natural_16
			-- Read a new 16-bit natural.
			-- Make result available in last_natural_16.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_natural_32
			-- Read a new 32-bit natural.
			-- Make result available in last_natural.
			-- Was declared in SOCKET as synonym of read_natural.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_natural_64
			-- Read a new 64-bit natural.
			-- Make result available in last_natural_64.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_natural_8
			-- Read a new 8-bit natural.
			-- Make result available in last_natural_8.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_real
			-- Read a new real.
			-- Make result available in last_real.
			-- Was declared in SOCKET as synonym of readreal.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read

	read_stream (nb_char: INTEGER_32)
			-- Read a string of at most `nb_char' characters.
			-- Make result available in last_string.
			-- Was declared in SOCKET as synonym of readstream.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from SOCKET
			socket_exists: exists
			opened_for_read: is_open_read
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void

	read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER_32)
			-- Read at most `nb_bytes' bound bytes and make result
			-- available in `p' at position `start_pos'.
			-- (from SOCKET)
		require -- from IO_MEDIUM
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			nb_bytes_non_negative: nb_bytes >= 0
			is_readable: readable
		require else -- from SOCKET
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			nb_bytes_non_negative: nb_bytes >= 0
			socket_exists: exists
			opened_for_read: is_open_read
		ensure -- from IO_MEDIUM
			bytes_read_non_negative