+#
+## Socket function.
+#
+## This function uses the Socket module to create and listen to an UNIX socket.
+## It automatically accepts all incomming connections and pass the recieved
+## data messages to the the Message_Parser function which is also part of the
+## socket module.
+#
+## If a valid command has been sent through the socket, the corresponding event
+## will be enqueued into the shared event queue.
+#
+sub Socket () {
+ # Create the Server socket by calling the responsible function.
+ my $server = &Guardian::Socket::Server();
+
+ # Accept incomming connections from the socket.
+ while (my $connection = $server->accept()) {
+ # Autoflush the socket after the data
+ # has been recieved.
+ $connection->autoflush(1);
+
+ # Gather all data from the connection.
+ while (my $message = <$connection>) {
+ # Remove any newlines.
+ chomp($message);
+
+ # Send the recieved data message to the
+ # socket parser.
+ my $action = &Guardian::Socket::Message_Parser($message);
+
+ # If the parser returns to perform an action,
+ # add it to the main event queue.
+ if ($action) {
+ # Lock the queue.
+ lock($queue);
+
+ # Enqueue the returned action.
+ $queue->enqueue($action);
+ }
+ }
+ }
+}
+