Merge branch 'master' of ssh://bitsetter.de:8090/netsl

This commit is contained in:
tkarrass 2013-11-02 18:00:28 +01:00
commit 5653aea2d6
4 changed files with 32 additions and 61 deletions

View File

@ -5,31 +5,8 @@
#include <arpa/inet.h> // htonl
#include "msg.h"
#if INTERFACE
#define INITIAL_SIZE 32
struct Buffer {
int size;
void *data;
};
struct message {
uint32_t timestamp;
uint32_t width; // varies
uint32_t height; // normally 80
//char **image; // dimension is width x height
char *image; // dimension is width x height
};
#endif
int getBufferSize(struct message *msg) {
int ret;
ret = 4 + 4 + 4 + msg->width * msg->height;
return ret;
return 3*sizeof(uint32_t) + msg->width * msg->height;
}
void serialize (char *buf, struct message *msg) {
@ -50,7 +27,7 @@ void deserialize (struct message *msg, const char *buf) {
struct Buffer *new_buffer() {
struct Buffer *b = malloc(sizeof(Buffer));
b->data = malloc(INITIAL_SIZE);
b->data = malloc(0);
b->size = 0;
return b;
@ -60,7 +37,7 @@ void append_space(Buffer * b, int n) {
b->size += n;
b->data = realloc(b->data, b->size);
}
/*
void serialize_int(int x, Buffer * b) {
// htonl :: uint32_t -> uint32_t -- converts the parameter from host byte order to network byte order
//x = htonl(x);
@ -96,7 +73,7 @@ void serialize_message(struct message *msg, Buffer *b) {
serialize_string(msg->image[i], b);
}
/*
int main() {
Buffer *buf = new_buffer();

View File

@ -1,11 +1,9 @@
/* This file was automatically generated. Do not edit! */
typedef struct Buffer Buffer;
void append_space(Buffer *b,int n);
struct Buffer *new_buffer();
typedef struct message message;
void deserialize(struct message *msg,const char *buf);
void serialize(char *buf,struct message *msg);
int getBufferSize(struct message *msg);
struct Buffer {
int size;
void *data;
};
struct message {
uint32_t timestamp;
uint32_t width; // varies
@ -13,9 +11,14 @@ struct message {
//char **image; // dimension is width x height
char *image; // dimension is width x height
};
struct Buffer {
int size;
void *data;
};
#define INITIAL_SIZE 32
#define INTERFACE 0
int getBufferSize(struct message *msg);
void serialize(char *buf,struct message *msg);
void deserialize(struct message *msg,const char *buf);
struct Buffer *new_buffer();
void append_space(Buffer *b,int n);
void serialize_int(int x,Buffer *b);
void serialize_string(char *str,Buffer *b);
void serialize_message(struct message *msg,Buffer *b);

View File

@ -1,4 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

View File

@ -1,14 +1,6 @@
/* This file was automatically generated. Do not edit! */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
int run_client(const struct prog_info *pinfo,void(*framecallback)(long));
int run_server(const struct prog_info *pinfo);
#include <sys/socket.h> // struct sockaddr
void *get_in_addr(struct sockaddr *sa);
int run_server(const struct prog_info *pinfo);
int run_client(const struct prog_info *pinfo,void(*framecallback)(long));