forked from M-Labs/artiq
Rename {kserver → net_server}.{c,h}.
This commit is contained in:
parent
e8943a008c
commit
697b78ddf2
|
@ -1,6 +1,6 @@
|
||||||
include $(MSCDIR)/software/common.mak
|
include $(MSCDIR)/software/common.mak
|
||||||
|
|
||||||
OBJECTS := isr.o flash_storage.o clock.o rtiocrg.o elf_loader.o services.o session.o log.o test_mode.o kloader.o bridge_ctl.o mailbox.o ksupport_data.o kserver.o moninj.o main.o
|
OBJECTS := isr.o flash_storage.o clock.o rtiocrg.o elf_loader.o services.o session.o log.o test_mode.o kloader.o bridge_ctl.o mailbox.o ksupport_data.o net_server.o moninj.o main.o
|
||||||
OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o ttl.o dds.o
|
OBJECTS_KSUPPORT := ksupport.o exception_jmp.o exceptions.o mailbox.o bridge.o rtio.o ttl.o dds.o
|
||||||
|
|
||||||
CFLAGS += -Ilwip/src/include -Iliblwip
|
CFLAGS += -Ilwip/src/include -Iliblwip
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#ifndef __KSERVER_H
|
|
||||||
#define __KSERVER_H
|
|
||||||
|
|
||||||
void kserver_init(void);
|
|
||||||
void kserver_service(void);
|
|
||||||
|
|
||||||
#endif /* __KSERVER_H */
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "rtiocrg.h"
|
#include "rtiocrg.h"
|
||||||
#include "test_mode.h"
|
#include "test_mode.h"
|
||||||
#include "kserver.h"
|
#include "net_server.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "moninj.h"
|
#include "moninj.h"
|
||||||
|
|
||||||
|
@ -138,14 +138,14 @@ static void regular_main(void)
|
||||||
{
|
{
|
||||||
puts("Accepting sessions on Ethernet.");
|
puts("Accepting sessions on Ethernet.");
|
||||||
network_init();
|
network_init();
|
||||||
kserver_init();
|
net_server_init();
|
||||||
moninj_init();
|
moninj_init();
|
||||||
|
|
||||||
session_end();
|
session_end();
|
||||||
while(1) {
|
while(1) {
|
||||||
lwip_service();
|
lwip_service();
|
||||||
kloader_service_essential_kmsg();
|
kloader_service_essential_kmsg();
|
||||||
kserver_service();
|
net_server_service();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,19 +14,19 @@
|
||||||
#include <lwip/timers.h>
|
#include <lwip/timers.h>
|
||||||
|
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "kserver.h"
|
#include "net_server.h"
|
||||||
|
|
||||||
struct kserver_connstate {
|
struct net_server_connstate {
|
||||||
int magic_recognized;
|
int magic_recognized;
|
||||||
struct pbuf *rp;
|
struct pbuf *rp;
|
||||||
int rp_offset;
|
int rp_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct kserver_connstate *cs_new(void)
|
static struct net_server_connstate *cs_new(void)
|
||||||
{
|
{
|
||||||
struct kserver_connstate *cs;
|
struct net_server_connstate *cs;
|
||||||
|
|
||||||
cs = (struct kserver_connstate *)mem_malloc(sizeof(struct kserver_connstate));
|
cs = (struct net_server_connstate *)mem_malloc(sizeof(struct net_server_connstate));
|
||||||
if(!cs)
|
if(!cs)
|
||||||
return NULL;
|
return NULL;
|
||||||
cs->magic_recognized = 0;
|
cs->magic_recognized = 0;
|
||||||
|
@ -35,24 +35,24 @@ static struct kserver_connstate *cs_new(void)
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cs_free(struct kserver_connstate *cs)
|
static void cs_free(struct net_server_connstate *cs)
|
||||||
{
|
{
|
||||||
if(cs->rp)
|
if(cs->rp)
|
||||||
pbuf_free(cs->rp);
|
pbuf_free(cs->rp);
|
||||||
mem_free(cs);
|
mem_free(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char kserver_magic[] = "ARTIQ coredev\n";
|
static const char net_server_magic[] = "ARTIQ coredev\n";
|
||||||
|
|
||||||
static int magic_ok(struct kserver_connstate *cs)
|
static int magic_ok(struct net_server_connstate *cs)
|
||||||
{
|
{
|
||||||
return cs->magic_recognized >= 14;
|
return cs->magic_recognized >= 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct kserver_connstate *active_cs;
|
static struct net_server_connstate *active_cs;
|
||||||
static struct tcp_pcb *active_pcb;
|
static struct tcp_pcb *active_pcb;
|
||||||
|
|
||||||
static void kserver_close(struct kserver_connstate *cs, struct tcp_pcb *pcb)
|
static void net_server_close(struct net_server_connstate *cs, struct tcp_pcb *pcb)
|
||||||
{
|
{
|
||||||
if(cs == active_cs) {
|
if(cs == active_cs) {
|
||||||
session_end();
|
session_end();
|
||||||
|
@ -70,11 +70,11 @@ static void kserver_close(struct kserver_connstate *cs, struct tcp_pcb *pcb)
|
||||||
tcp_close(pcb);
|
tcp_close(pcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static err_t kserver_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
static err_t net_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||||
{
|
{
|
||||||
struct kserver_connstate *cs;
|
struct net_server_connstate *cs;
|
||||||
|
|
||||||
cs = (struct kserver_connstate *)arg;
|
cs = (struct net_server_connstate *)arg;
|
||||||
if(p) {
|
if(p) {
|
||||||
if(cs->rp)
|
if(cs->rp)
|
||||||
pbuf_cat(cs->rp, p);
|
pbuf_cat(cs->rp, p);
|
||||||
|
@ -83,11 +83,11 @@ static err_t kserver_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t
|
||||||
cs->rp_offset = 0;
|
cs->rp_offset = 0;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
kserver_close(cs, pcb);
|
net_server_close(cs, pcb);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static err_t kserver_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
|
static err_t net_server_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||||
{
|
{
|
||||||
session_ack_mem(len);
|
session_ack_mem(len);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
|
@ -95,13 +95,13 @@ static err_t kserver_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||||
|
|
||||||
static void tcp_pcb_service(void *arg, struct tcp_pcb *pcb)
|
static void tcp_pcb_service(void *arg, struct tcp_pcb *pcb)
|
||||||
{
|
{
|
||||||
struct kserver_connstate *cs;
|
struct net_server_connstate *cs;
|
||||||
int remaining_in_pbuf;
|
int remaining_in_pbuf;
|
||||||
char *rpp;
|
char *rpp;
|
||||||
struct pbuf *next;
|
struct pbuf *next;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
cs = (struct kserver_connstate *)arg;
|
cs = (struct net_server_connstate *)arg;
|
||||||
|
|
||||||
while(cs->rp) {
|
while(cs->rp) {
|
||||||
remaining_in_pbuf = cs->rp->len - cs->rp_offset;
|
remaining_in_pbuf = cs->rp->len - cs->rp_offset;
|
||||||
|
@ -116,20 +116,20 @@ static void tcp_pcb_service(void *arg, struct tcp_pcb *pcb)
|
||||||
} else if(r == 0)
|
} else if(r == 0)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
kserver_close(cs, pcb);
|
net_server_close(cs, pcb);
|
||||||
} else {
|
} else {
|
||||||
if(rpp[cs->rp_offset] == kserver_magic[cs->magic_recognized]) {
|
if(rpp[cs->rp_offset] == net_server_magic[cs->magic_recognized]) {
|
||||||
cs->magic_recognized++;
|
cs->magic_recognized++;
|
||||||
if(magic_ok(cs)) {
|
if(magic_ok(cs)) {
|
||||||
if(active_cs)
|
if(active_cs)
|
||||||
kserver_close(active_cs, active_pcb);
|
net_server_close(active_cs, active_pcb);
|
||||||
session_start();
|
session_start();
|
||||||
active_cs = cs;
|
active_cs = cs;
|
||||||
active_pcb = pcb;
|
active_pcb = pcb;
|
||||||
tcp_sent(pcb, kserver_sent);
|
tcp_sent(pcb, net_server_sent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
kserver_close(cs, pcb);
|
net_server_close(cs, pcb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remaining_in_pbuf--;
|
remaining_in_pbuf--;
|
||||||
|
@ -150,41 +150,41 @@ static void tcp_pcb_service(void *arg, struct tcp_pcb *pcb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kserver_err(void *arg, err_t err)
|
static void net_server_err(void *arg, err_t err)
|
||||||
{
|
{
|
||||||
struct kserver_connstate *cs;
|
struct net_server_connstate *cs;
|
||||||
|
|
||||||
cs = (struct kserver_connstate *)arg;
|
cs = (struct net_server_connstate *)arg;
|
||||||
cs_free(cs);
|
cs_free(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct tcp_pcb *listen_pcb;
|
static struct tcp_pcb *listen_pcb;
|
||||||
|
|
||||||
static err_t kserver_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
|
static err_t net_server_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||||
{
|
{
|
||||||
struct kserver_connstate *cs;
|
struct net_server_connstate *cs;
|
||||||
|
|
||||||
cs = cs_new();
|
cs = cs_new();
|
||||||
if(!cs)
|
if(!cs)
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
tcp_accepted(listen_pcb);
|
tcp_accepted(listen_pcb);
|
||||||
tcp_arg(newpcb, cs);
|
tcp_arg(newpcb, cs);
|
||||||
tcp_recv(newpcb, kserver_recv);
|
tcp_recv(newpcb, net_server_recv);
|
||||||
tcp_err(newpcb, kserver_err);
|
tcp_err(newpcb, net_server_err);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kserver_init(void)
|
void net_server_init(void)
|
||||||
{
|
{
|
||||||
listen_pcb = tcp_new();
|
listen_pcb = tcp_new();
|
||||||
tcp_bind(listen_pcb, IP_ADDR_ANY, 1381);
|
tcp_bind(listen_pcb, IP_ADDR_ANY, 1381);
|
||||||
listen_pcb = tcp_listen(listen_pcb);
|
listen_pcb = tcp_listen(listen_pcb);
|
||||||
tcp_accept(listen_pcb, kserver_accept);
|
tcp_accept(listen_pcb, net_server_accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern struct tcp_pcb *tcp_active_pcbs;
|
extern struct tcp_pcb *tcp_active_pcbs;
|
||||||
|
|
||||||
void kserver_service(void)
|
void net_server_service(void)
|
||||||
{
|
{
|
||||||
struct tcp_pcb *pcb;
|
struct tcp_pcb *pcb;
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -208,7 +208,7 @@ void kserver_service(void)
|
||||||
session_ack_data(len);
|
session_ack_data(len);
|
||||||
}
|
}
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
kserver_close(active_cs, active_pcb);
|
net_server_close(active_cs, active_pcb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef __NET_SERVER_H
|
||||||
|
#define __NET_SERVER_H
|
||||||
|
|
||||||
|
void net_server_init(void);
|
||||||
|
void net_server_service(void);
|
||||||
|
|
||||||
|
#endif /* __NET_SERVER_H */
|
Loading…
Reference in New Issue