Factor out net services so they're not tied to a static array.
This lets different things dynamically create the services they need, and sorts out the horrible hacks that view1090 used to make outgoing connections. Now you can explicitly create a service and tell it to make an outgoing connection. This means that view1090 can now just set all the ports to zero (to disable the listeners), do a normal net init, then explicitly construct the beast input service without a listener and tell it to make a connection as needed.
This commit is contained in:
parent
5fa039a2d4
commit
278448179d
5 changed files with 360 additions and 379 deletions
41
dump1090.h
41
dump1090.h
|
|
@ -82,7 +82,8 @@
|
|||
#include "winstubs.h" //Put everything Windows specific in here
|
||||
#endif
|
||||
|
||||
#include <rtl-sdr.h>
|
||||
// Avoid a dependency on rtl-sdr except where it's really needed.
|
||||
typedef struct rtlsdr_dev rtlsdr_dev_t;
|
||||
|
||||
// ============================= #defines ===============================
|
||||
|
||||
|
|
@ -212,6 +213,7 @@
|
|||
|
||||
#include "util.h"
|
||||
#include "anet.h"
|
||||
#include "net_io.h"
|
||||
#include "crc.h"
|
||||
#include "demod_2000.h"
|
||||
#include "demod_2400.h"
|
||||
|
|
@ -222,24 +224,6 @@
|
|||
|
||||
//======================== structure declarations =========================
|
||||
|
||||
// Structure used to describe a networking client
|
||||
struct client {
|
||||
struct client* next; // Pointer to next client
|
||||
int fd; // File descriptor
|
||||
int service; // TCP port the client is connected to
|
||||
int buflen; // Amount of data on buffer
|
||||
char buf[MODES_CLIENT_BUF_SIZE+1]; // Read buffer
|
||||
};
|
||||
|
||||
// Common writer state for all output sockets of one type
|
||||
struct net_writer {
|
||||
int socket; // listening socket FD, used to identify the owning service
|
||||
int connections; // number of active clients
|
||||
void *data; // shared write buffer, sized MODES_OUT_BUF_SIZE
|
||||
int dataUsed; // number of bytes of write buffer currently used
|
||||
uint64_t lastWrite; // time of last write to clients
|
||||
};
|
||||
|
||||
// Structure representing one magnitude buffer
|
||||
struct mag_buf {
|
||||
uint16_t *data; // Magnitude data. Starts with Modes.trailing_samples worth of overlap from the previous block
|
||||
|
|
@ -287,10 +271,8 @@ struct { // Internal state
|
|||
|
||||
// Networking
|
||||
char aneterr[ANET_ERR_LEN];
|
||||
struct net_service *services; // Active services
|
||||
struct client *clients; // Our clients
|
||||
int ris; // Raw input listening socket
|
||||
int bis; // Beast input listening socket
|
||||
int https; // HTTP listening socket
|
||||
|
||||
struct net_writer raw_out; // Raw output
|
||||
struct net_writer beast_out; // Beast-format output
|
||||
|
|
@ -448,21 +430,6 @@ void useModesMessage (struct modesMessage *mm);
|
|||
//
|
||||
void interactiveShowData(void);
|
||||
|
||||
//
|
||||
// Functions exported from net_io.c
|
||||
//
|
||||
void modesInitNet (void);
|
||||
void modesQueueOutput (struct modesMessage *mm);
|
||||
void modesReadFromClient(struct client *c, char *sep, int(*handler)(struct client *, char *));
|
||||
void modesNetPeriodicWork (void);
|
||||
int decodeBinMessage (struct client *c, char *p);
|
||||
|
||||
void writeJsonToFile(const char *file, char * (*generator) (const char*,int*));
|
||||
char *generateAircraftJson(const char *url_path, int *len);
|
||||
char *generateReceiverJson(const char *url_path, int *len);
|
||||
char *generateStatsJson(const char *url_path, int *len);
|
||||
char *generateHistoryJson(const char *url_path, int *len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue