try different stuff with tcp

This commit is contained in:
PolynomialDivision 2018-02-11 23:11:43 +01:00
parent 6e03655253
commit 04f1410b8a
2 changed files with 11 additions and 7 deletions

View file

@ -1,12 +1,14 @@
#ifndef DAWN_TCPSOCKET_H #ifndef DAWN_TCPSOCKET_H
#define DAWN_TCPSOCKET_H #define DAWN_TCPSOCKET_H
#include <libubox/ustream.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <pthread.h> #include <pthread.h>
struct network_con_s { struct network_con_s {
int sockfd; int sockfd;
struct sockaddr_in sock_addr; struct sockaddr_in sock_addr;
struct ustream_fd s;
}; };
void *run_tcp_socket(void *arg); void *run_tcp_socket(void *arg);

View file

@ -34,7 +34,7 @@ struct client {
int ctr; int ctr;
int counter; int counter;
}; };
/*
static void client_close(struct ustream *s) { static void client_close(struct ustream *s) {
struct client *cl = container_of(s, struct client *cl = container_of(s,
struct client, s.stream); struct client, s.stream);
@ -49,7 +49,7 @@ static void client_close(struct ustream *s) {
pthread_mutex_unlock(&tcp_array_mutex); pthread_mutex_unlock(&tcp_array_mutex);
free(cl); free(cl);
}*/ }
static void client_notify_write(struct ustream *s, int bytes) { static void client_notify_write(struct ustream *s, int bytes) {
return; return;
@ -65,8 +65,8 @@ static void client_notify_state(struct ustream *s) {
fprintf(stderr, "eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr); fprintf(stderr, "eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr);
// TODO: REMOVE CLIENT FROM LIST! OR NOT? // TODO: REMOVE CLIENT FROM LIST! OR NOT?
//if (!s->w.data_bytes) if (!s->w.data_bytes)
// return client_close(s); return client_close(s);
} }
@ -145,7 +145,7 @@ int run_server(int port) {
} }
int add_tcp_conncection(char *ipv4, int port) { int add_tcp_conncection(char *ipv4, int port) {
int sockfd; //int sockfd;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
char port_str[12]; char port_str[12];
@ -162,13 +162,15 @@ int add_tcp_conncection(char *ipv4, int port) {
return 0; return 0;
} }
sockfd = usock(USOCK_TCP, ipv4, port_str); int sockfd = usock(USOCK_TCP | USOCK_NONBLOCK, ipv4, port_str);
struct network_con_s tmp = struct network_con_s tmp =
{ {
.sock_addr = serv_addr, .sock_addr = serv_addr,
.sockfd = sockfd .sockfd = sockfd
}; };
//tmp.s.fd.fd = usock(USOCK_TCP | USOCK_NONBLOCK, ipv4, port_str);
//uloop_fd_add(&tmp.s.fd, ULOOP_WRITE);
//tmp.sockfd = tmp.s.fd.fd;
insert_to_tcp_array(tmp); insert_to_tcp_array(tmp);