TinyMUSH 3.3
TinyMUSH Server
|
BSD-style network and signal routines. More...
#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <errno.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <ctype.h>
#include <signal.h>
Functions | |
MSGQ_DNSRESOLVER | mk_msgq_dnsresolver (const char *addr) |
Convert a text ip address to binary format for the message queue. Not used for now. More... | |
void * | dnsResolver (void *args) |
DNS Resolver thread. More... | |
void | check_dnsResolver_status (dbref player, __attribute__((unused)) dbref cause, __attribute__((unused)) int key) |
int | make_socket (int port) |
Create a socket. More... | |
void | shovechars (int port) |
Process input form a port and feed to the engine. More... | |
DESC * | new_connection (int sock) |
Handle new connections. More... | |
char * | connReasons (int reason) |
(Dis)connect reasons that get written to the logfile More... | |
char * | connMessages (int reason) |
(Dis)connect reasons that get fed to A_A(DIS)CONNECT via announce_connattr More... | |
void | shutdownsock (DESC *d, int reason) |
Handle disconnections. More... | |
void | make_nonblocking (int s) |
Make a socket nonblocking if needed. More... | |
DESC * | initializesock (int s, struct sockaddr_in *a) |
Initialize a socket. More... | |
int | process_output (DESC *d) |
Process output to a socket. More... | |
int | process_input (DESC *d) |
Process input from a socket. More... | |
void | close_sockets (int emergency, char *message) |
Close all sockets. More... | |
void | emergency_shutdown (void) |
Suggar we're going down!!! More... | |
void | report (void) |
Write a report to log. More... | |
void | sighandler (int sig) |
Handle system signals. More... | |
void | set_signals (void) |
Set the signals handlers. More... | |
void | unset_signals (void) |
Unset the signal handlers. More... | |
void | check_panicking (int sig) |
Check if we are panicking. More... | |
void | log_signal (const char *signame) |
Log the signal we caugh. More... | |
Variables | |
int | sock = 0 |
int | ndescriptors = 0 |
int | maxd = 0 |
DESC * | descriptor_list = NULL |
key_t | msgq_Key = 0 |
Message queue related. More... | |
BSD-style network and signal routines.
void check_dnsResolver_status | ( | dbref | player, |
__attribute__((unused)) dbref | cause, | ||
__attribute__((unused)) int | key | ||
) |
void check_panicking | ( | int | sig | ) |
Check if we are panicking.
sig | Signal that triggered the check |
If we are panicking, turn off signal catching and resignal
void close_sockets | ( | int | emergency, |
char * | message | ||
) |
Close all sockets.
emergency | Closing caused by emergency? |
message | Message to send before closing |
char * connMessages | ( | int | reason | ) |
(Dis)connect reasons that get fed to A_A(DIS)CONNECT via announce_connattr
message | reason ID |
char * connReasons | ( | int | reason | ) |
(Dis)connect reasons that get written to the logfile
reason | reason ID |
void * dnsResolver | ( | void * | args | ) |
DNS Resolver thread.
args | Message queue key |
void emergency_shutdown | ( | void | ) |
Suggar we're going down!!!
DESC * initializesock | ( | int | s, |
struct sockaddr_in * | a | ||
) |
Initialize a socket.
s | Socket file descriptor |
a | Socket internet address descriptor |
void log_signal | ( | const char * | signame | ) |
Log the signal we caugh.
signame | Signal name. |
void make_nonblocking | ( | int | s | ) |
Make a socket nonblocking if needed.
s | Socket to modify. |
int make_socket | ( | int | port | ) |
Create a socket.
port | Port for the socket |
MSGQ_DNSRESOLVER mk_msgq_dnsresolver | ( | const char * | addr | ) |
Convert a text ip address to binary format for the message queue. Not used for now.
addr | IP address |
DESC * new_connection | ( | int | sock | ) |
Handle new connections.
sock | Socket to listen for new connections |
Ask DNS Resolver for hostname
int process_input | ( | DESC * | d | ) |
Process input from a socket.
d | Socket description |
int process_output | ( | DESC * | d | ) |
Process output to a socket.
d | Socket description |
void report | ( | void | ) |
Write a report to log.
void set_signals | ( | void | ) |
Set the signals handlers.
We have to reset our signal mask, because of the possibility that we triggered a restart on a SIGUSR1. If we did so, then the signal became blocked, and stays blocked, since control never returns to the caller; i.e., further attempts to send a SIGUSR1 would fail.
void shovechars | ( | int | port | ) |
Process input form a port and feed to the engine.
port | Port to listen |
Start the message queue.
Start the DNS resolver thread
We've gotten a signal to dump flatfiles
test for events
any queued robot commands waiting?
Listen for new connections if there are free descriptors
Mark sockets that we want to test for change in status
Wait for something to happen
This one is bad, as it results in a spiral of doom, unless we can figure out what the bad file descriptor is and get rid of it.
It's a player. Just toss the connection.
We didn't figured it out, well that's it, game over.
if !found then time for robot commands
Check if we have something from the DNS Resolver.
Check for new connection requests
Check for activity on user sockets
Process input from sockets with pending input
Undo AutoDark
Process received data
Process output for sockets with pending output
Stop the DNS message queue.
Wait for the thread to end.
void shutdownsock | ( | DESC * | d, |
int | reason | ||
) |
Handle disconnections.
d | Connection descriptor |
reason | Reason for disconnection |
Do the disconnect stuff if we aren't doing a LOGOUT (which keeps the connection open so the player can connect to a different character).
If the socket died, there's no reason to display the quit file.
If requested, write an accounting record of the form: Plyr# Flags Cmds ConnTime Loc Money [Site] <DiscRsn> Name
If this was our only connection, get out of interactive mode.
Free_RegData
Free_RegDataStruct
void sighandler | ( | int | sig | ) |
Handle system signals.
sig | Signal to handle |
< Normal restart now
< Dump a flatfile soon
< Timer
< Change in child status
< Dump database soon
< Force a live backup
< Normal shutdown soon
< Killed shutdown now
< Panic save + restart now, or coredump now
Not good, Don't sync, restart using older db.
Try our best to dump a usable core by generating a second signal with the SIG_DFL action.
In the parent process (easier to follow with gdb), we're about to return from this signal handler and hope that a second signal is delivered. Meanwhile let's close all our files to avoid corrupting the child process.
< Coredump now
void unset_signals | ( | void | ) |
Unset the signal handlers.
DESC* descriptor_list = NULL |
Descriptor list
int maxd = 0 |
Max Descriptors
key_t msgq_Key = 0 |
Message queue related.
Message Queue Key
int ndescriptors = 0 |
New Descriptor
int sock = 0 |