indexing description: "[ A UDP packet that contains data to be sent over a network using the non-reliable User Datagram Protocol. ]" date: "$Date$" revision: "$Revision$" class EM_UDP_PACKET inherit EM_NETWORK_CONSTANTS export {NONE} all end SDL_NET_FUNCTIONS export {NONE} all end EXCEPTIONS export {NONE} all end create make create {EM_SIMPLE_UDP_SOCKET, EM_UDP_SOCKET} make_from_struct feature {NONE}-- Initialisation make is -- Creates a new UDP packet. do create udp_packet_struct.make_new_unshared udp_packet_struct.set_channel (-1) end make_from_struct(a_packet_struct: UDPPACKET_STRUCT) is -- Copy data from existing UDPSTRUCT local an_ip_address_struct: IPADDRESS_STRUCT do create an_ip_address_struct.make_shared (a_packet_struct.address) make set_address (create {EM_INET_SOCKET_ADDRESS}.make_by_struct (an_ip_address_struct)) put_string (get_string_from_pointer(a_packet_struct.data, a_packet_struct.len)) end feature -- Status is_empty: BOOLEAN is -- True, if the current packet is empty. do Result := count = 0 end feature -- Access item: STRING is -- Returns the packet data as a string. do Result := data ensure result_correct: Result = data end address: EM_INET_SOCKET_ADDRESS -- Returns the address of the packet. -- If you've just received the packet, this is the address of the source host. count: INTEGER is -- Represents the packet's size in bytes. do Result := data.count end feature -- Element change set_address (an_inet_socket_address: EM_INET_SOCKET_ADDRESS) is -- Sets `an_inet_socket_address' as the address of the packet. -- If you prepare a packet for sending, this will be the destination -- address the packet will be sent to. require an_inet_socket_address_not_void: an_inet_socket_address /= Void do address := an_inet_socket_address udp_packet_struct.set_address (address.ip_address_struct.item) ensure address_set: address = an_inet_socket_address end put_string (a_string: STRING) is -- Sets `a_string' as the packet data. require a_string_not_void: a_string /= Void do create cstr.make (a_string) data := a_string udp_packet_struct.set_data (cstr.item) udp_packet_struct.set_len (cstr.count) ensure data_correct_set: data = a_string end -- TODO: implement -- put_buffer(a_buffer : KI_BUFFER[CHARACTER]) is -- -- creates a packet from a buffer -- do -- -- end -- feature {EM_SIMPLE_UDP_SOCKET, EM_UDP_SOCKET} -- Implementation udp_packet_struct : UDPPACKET_STRUCT -- C struct representation of the packet. feature {NONE} -- Implementation data: STRING -- The data of the packet. cstr: C_STRING -- C String -- Avoids use of UDPFreepacket get_string_from_pointer (a_pointer: POINTER; a_length: INTEGER): STRING is -- entweder wir verwerfen den KL_STRING_INPUT_STREAM oder wir -- finden vielleicht mal noch etwas besseres, schnelleres verfahren local i: INTEGER tmp: MANAGED_POINTER do create tmp.share_from_pointer (a_pointer, a_length) create Result.make_empty from i := 0 until i >= a_length loop Result.extend (tmp.read_character (i)) i := i + 1 end end invariant invariant_clause: True -- Your invariant here end