indexing description: "[ Represents a connection to a remote peer. Input and output is not directly done via the connection but via the groups a connection belongs to: Every connection has a predefined `personal_group' that can be used for data sending and receival with only one specific peer (that is the other side of the connection). A connection may join multiple groups. You can also define your own group. Data transfer on such a group concerns all connections that have joined the corresponding group. See EM_NET_GROUP for further details. ]" date: "$Date$" revision: "$Revision$" class EM_NET_CONNECTION inherit EM_NET_EVENT_PROCESSOR rename make as make_event_processor end create make feature -- Initialization make is -- Initialisation do make_event_processor create timeout_event create groups.make max_idle_time := 5000 end feature -- Actions join (a_group: EM_NET_GROUP) is -- Join `a_group'. require a_group_not_void: a_group /= Void not_already_member_of_a_group: not a_group.has_connection(Current) do a_group.add_connection(Current) groups.put_last(a_group) check groups_updated: groups.has(a_group) end ensure group_joined: a_group.has_connection(Current) end leave (a_group: EM_NET_GROUP) is -- Leave `a_group'. require a_group_not_void: a_group /= Void member_of_a_group: a_group.has_connection(Current) do check groups_updated: groups.has(a_group) end a_group.remove_connection(Current) groups.delete(a_group) check groups_updated: not groups.has(a_group) end ensure group_left: not a_group.has_connection(Current) end leave_all_groups is -- Leave all groups. do from until groups.count = 0 loop leave (groups.first) end end feature -- Element change set_socket_address(a_socket_address: EM_INET_SOCKET_ADDRESS) is -- Set `socket_address' to `a_socket_address'. require a_socket_address_not_void: a_socket_address /= Void do socket_address := a_socket_address ensure socket_address_set: socket_address = a_socket_address end set_personal_group(a_personal_group: EM_NET_GROUP) is -- Set `personal_group' to `a_personal_group'. require a_personal_group_not_void: a_personal_group /= Void do personal_group := a_personal_group ensure personal_group_set: personal_group = a_personal_group end set_last_update(a_receive_time: INTEGER) is -- Set `receive_time' to `a_receive_time'. do last_receive_time := a_receive_time ensure last_update_set: last_receive_time = a_receive_time end set_max_idle_time(an_idle_time: INTEGER) is -- Set `socket_address' to `a_socket_address'. require an_natural_idle_time: an_idle_time >= 0 do max_idle_time := an_idle_time ensure max_idle_time_set: max_idle_time = an_idle_time end feature -- Attributes socket_address: EM_INET_SOCKET_ADDRESS -- Socket address personal_group: EM_NET_GROUP -- Personal group groups: DS_LINKED_LIST[EM_NET_GROUP] -- List of groups that this connection belongs to last_receive_time: INTEGER -- Last time of incoming network activity in ms max_idle_time: INTEGER -- Max idle duration -- If max_idle_time is exceeded a timeout event will be generated. timeout_event: EM_EVENT_CHANNEL[TUPLE[EM_NET_CONNECTION]] -- Timeout event feature {NONE} -- Implementation invariant invariant_clause: True -- Your invariant here end