forked from M-Labs/artiq
Rename {kserver → net_server}.{c,h}.
This commit is contained in:
parent
8d1663394b
commit
33531c2f3b
@ -1,6 +1,6 @@
|
||||
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
|
||||
|
||||
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 "rtiocrg.h"
|
||||
#include "test_mode.h"
|
||||
#include "kserver.h"
|
||||
#include "net_server.h"
|
||||
#include "session.h"
|
||||
#include "moninj.h"
|
||||
|
||||
@ -138,14 +138,14 @@ static void regular_main(void)
|
||||
{
|
||||
puts("Accepting sessions on Ethernet.");
|
||||
network_init();
|
||||
kserver_init();
|
||||
net_server_init();
|
||||
moninj_init();
|
||||
|
||||
session_end();
|
||||
while(1) {
|
||||
lwip_service();
|
||||
kloader_service_essential_kmsg();
|
||||
kserver_service();
|
||||
net_server_service();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,19 +14,19 @@
|
||||
#include <lwip/timers.h>
|
||||
|
||||
#include "session.h"
|
||||
#include "kserver.h"
|
||||
#include "net_server.h"
|
||||
|
||||
struct kserver_connstate {
|
||||
struct net_server_connstate {
|
||||
int magic_recognized;
|
||||
struct pbuf *rp;
|
||||
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)
|
||||
return NULL;
|
||||
cs->magic_recognized = 0;
|
||||
@ -35,24 +35,24 @@ static struct kserver_connstate *cs_new(void)
|
||||
return cs;
|
||||
}
|
||||
|
||||
static void cs_free(struct kserver_connstate *cs)
|
||||
static void cs_free(struct net_server_connstate *cs)
|
||||
{
|
||||
if(cs->rp)
|
||||
pbuf_free(cs->rp);
|
||||
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;
|
||||
}
|
||||
|
||||
static struct kserver_connstate *active_cs;
|
||||
static struct net_server_connstate *active_cs;
|
||||
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) {
|
||||
session_end();
|
||||
@ -70,11 +70,11 @@ static void kserver_close(struct kserver_connstate *cs, struct tcp_pcb *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(cs->rp)
|
||||
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;
|
||||
}
|
||||
} else
|
||||
kserver_close(cs, pcb);
|
||||
net_server_close(cs, pcb);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
struct kserver_connstate *cs;
|
||||
struct net_server_connstate *cs;
|
||||
int remaining_in_pbuf;
|
||||
char *rpp;
|
||||
struct pbuf *next;
|
||||
int r;
|
||||
|
||||
cs = (struct kserver_connstate *)arg;
|
||||
cs = (struct net_server_connstate *)arg;
|
||||
|
||||
while(cs->rp) {
|
||||
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)
|
||||
return;
|
||||
else
|
||||
kserver_close(cs, pcb);
|
||||
net_server_close(cs, pcb);
|
||||
} 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++;
|
||||
if(magic_ok(cs)) {
|
||||
if(active_cs)
|
||||
kserver_close(active_cs, active_pcb);
|
||||
net_server_close(active_cs, active_pcb);
|
||||
session_start();
|
||||
active_cs = cs;
|
||||
active_pcb = pcb;
|
||||
tcp_sent(pcb, kserver_sent);
|
||||
tcp_sent(pcb, net_server_sent);
|
||||
}
|
||||
} else {
|
||||
kserver_close(cs, pcb);
|
||||
net_server_close(cs, pcb);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
if(!cs)
|
||||
return ERR_MEM;
|
||||
tcp_accepted(listen_pcb);
|
||||
tcp_arg(newpcb, cs);
|
||||
tcp_recv(newpcb, kserver_recv);
|
||||
tcp_err(newpcb, kserver_err);
|
||||
tcp_recv(newpcb, net_server_recv);
|
||||
tcp_err(newpcb, net_server_err);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void kserver_init(void)
|
||||
void net_server_init(void)
|
||||
{
|
||||
listen_pcb = tcp_new();
|
||||
tcp_bind(listen_pcb, IP_ADDR_ANY, 1381);
|
||||
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;
|
||||
|
||||
void kserver_service(void)
|
||||
void net_server_service(void)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
void *data;
|
||||
@ -208,7 +208,7 @@ void kserver_service(void)
|
||||
session_ack_data(len);
|
||||
}
|
||||
if(len < 0)
|
||||
kserver_close(active_cs, active_pcb);
|
||||
net_server_close(active_cs, active_pcb);
|
||||
}
|
||||
}
|
||||
|
7
soc/runtime/net_server.h
Normal file
7
soc/runtime/net_server.h
Normal file
@ -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
Block a user