Commit 175509fe authored by Zack Wong's avatar Zack Wong

Initial Commit

parents
x64/
.vs
*.vcxproj*
*.pyproj
*.tlog
*.sln
server/server
bin/
obj/
server/obj
.vscode
*.code-workspace
server/prof/massif.*
fastclient/fastclient
server
# LaTeX temporary files
*.aux
*.log
*.toc
*.xdv
# Latexmk
*.fdb_latexmk
# SyncTeX
*.synctex.gz
# LaTeX Beamer
*.snm
*.vrb
*.nav
*.out
# BibTeX
*.bbl
*.blg
This diff is collapsed.
README
======
This Solution is composed of 4 distinct projects. The Server and FastClient
projects each have Makefiles that can be used to build the respective projects.
**NOTE**: Only the report/ and server/ directories are for assessment, all other
documents are supplementary.
Compiled output can be found in the root directory of each project.
Server
------
This project contains the actual server to be assessed.
It is written in `C11` and requires GNU extensions to compile.
A makefile is included to build the project. It will only
build an run on Linux systems.
FastClient
----------
This is a sample multithreaded client written in `C++11` that is
extended mode compatible. It is **not intended for assessment** and
is provided simply to demonstrate the extended features of the server.
PyClient
--------
Another client, **not intended for assessment**, this time written in Python.
it is flexible and allows a user to form custom hardcoded test scenario's,
however it is not very efficient and struggles to support more that 100
clients on a moderately powerful machine.
Report
------
This is the project Report and its respective source code.
The report is provided precompiled, however should you wish to build it
yourself, `Xelatex` or `LuaTex` must be used.
vpath %.c src
vpath %.h src
PROJECT = icpl
HEADERS = $(wildcard src/*.h)
SRC = $(wildcard src/*.c)
OBJ = $(addprefix obj/,$(notdir $(SRC:.c=.o)))
CFLAGS = -std=gnu11 -Wall -fpic
release: CFLAGS += -O3
release: $(PROJECT)
debug: CFLAGS += -g
debug: $(PROJECT)
profile: CFLAGS += -g -pg
profile: $(PROJECT)
rebuild: clean release
$(PROJECT) : $(OBJ) | obj/
$(CC) $(CFLAGS) -shared -o lib$(PROJECT).so $(OBJ)
obj/%.o : %.c %.h $(HEADERS) | obj/
$(CC) $(CFLAGS) -o [email protected] -c $<
obj/%.o : %.c $(HEADERS) | obj/
$(CC) $(CFLAGS) -o [email protected] -c $<
obj/:
mkdir -p obj
clean:
rm -f $(PROJECT) $(OBJ)
vpath %.c src
vpath %.h src
PROJECT = icpl
HEADERS = $(wildcard src/*.h)
SRC = $(wildcard src/*.c)
OBJ = $(addprefix obj/,$(notdir $(SRC:.c=.o)))
CFLAGS = -std=gnu11 -Wall -fpic
release: CFLAGS += -O3
release: $(PROJECT)
debug: CFLAGS += -g
debug: $(PROJECT)
profile: CFLAGS += -g -pg
profile: $(PROJECT)
rebuild: clean release
$(PROJECT) : $(OBJ) | obj/
$(CC) $(CFLAGS) -o lib$(PROJECT).so $(OBJ) -lm
obj/%.o : %.c %.h $(HEADERS) | obj/
$(CC) $(CFLAGS) -o [email protected] -c $<
obj/%.o : %.c $(HEADERS) | obj/
$(CC) $(CFLAGS) -o [email protected] -c $<
obj/:
mkdir -p obj
clean:
rm -f $(PROJECT) $(OBJ)
#include "pane.h"
#define INPT A_UNDERLINE | COLOR_PAIR(6)
#define TEXT(c) A_PROTECT | COLOR_PAIR(c)
#define HGT 23
struct {
bool isInsert;
char inhibit[9];
}status = {
false,
"",
};
void draw(Screen *scr) {
size_t oldy, oldx;
getyx(stdscr, oldy, oldx);
for (int i = 0; scr->flds[i].type != END; ++i) {
Field* fld = &scr->flds[i];
switch (fld->type) {
case INP:
move(fld->y, fld->x);
attron(fld->attr);
addstr(fld->text);
for (int i = strlen(fld->text); i < fld->len; i++) addch(' ');
break;
case LBL:
move(fld->y, fld->x);
attron(fld->attr);
addstr(fld->text);
break;
case BTN:
move(0, fld->x);
attron(TEXT(7));
addstr(fld->text);
mvchgat(0, fld->x + fld->len, 1, A_UNDERLINE, 7, NULL);
break;
case RLR:
move(fld->y, fld->x);
attron(fld->attr);
hline(NCURSES_ACS(*fld->text),fld->len);
break;
default:
break;
}
standend();
}
move(oldy, oldx);
}
void init() {
initscr();
noecho();
cbreak();
keypad(stdscr, true);
curs_set(1);
/* COLOUR INIT */
start_color();
init_pair(8, COLOR_BLACK, COLOR_WHITE);
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_BLACK);
init_pair(4, COLOR_BLUE, COLOR_BLACK);
init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
init_pair(6, COLOR_CYAN, COLOR_BLACK);
init_pair(7, COLOR_WHITE, COLOR_BLACK);
/* END COLOUR INIT */
}
void draw_status(int y, int x) {
attron(TEXT(2));
mvhline(HGT,0,'_',80);
mvaddstr(HGT + 1, 8, status.inhibit);
mvaddstr(HGT + 1, 52, (status.isInsert ? "I" : "OVR"));
mvprintw(HGT+1, 74, "%02i,%02i", y + 1, x + 1);
standend();
}
#define TXTOPT "Option ===>"
#define TXTCMD "Command ===>"
#define TXTHDR "ISPF Primary Option Menu"
Field menuFlds[] = {
/* TYPE |ROW|COL|LEN| TXET | ATTR | NXT */
/******************* MENU BAR **********************/
{ BTN , 0, 3, 0,"Menu" , A_NORMAL , },
{ BTN , 0, 9, 0,"Utilities" , A_NORMAL , },
{ BTN , 0, 20, 0,"Compilers" , A_NORMAL , },
{ BTN , 0, 31, 0,"Options" , A_NORMAL , },
{ BTN , 0, 40, 0,"Status" , A_NORMAL , },
{ BTN , 0, 48, 0,"Help" , A_NORMAL , },
/******************** INPUTS ***********************/
{ INP , 3, 13, 66, "" , INPT , -1 },
/******************** LABELS ***********************/
{ LBL , 2, 28, 0,TXTHDR , TEXT(4) , },
{ LBL , 3, 1, 0,TXTOPT , TEXT(2) , },
/******************** RULERS ***********************/
{ RLR, 1, 1, 78, "q" , TEXT(4) , },
{END}
};
Screen* init_screen(Field *fields) {
Screen* scr;
scr = (Screen*) calloc(1, sizeof(Screen));
scr->flds = fields;
int i = 0;
while (fields[i].type != INP) { ++i; }
scr->inps = &fields[i];
return scr;
}
int start() {
init();
Screen *menu = init_screen(menuFlds);
draw(menu);
int x, y;
move(3, 13);
getyx(stdscr,y, x);
draw_status(y, x);
int chr = mvinch(y,x); // save attr
chtype clr = chr & A_COLOR;
chtype attr = chr & A_ATTRIBUTES;
chgat(1, A_REVERSE | attr, 0, NULL); // set block
while (1) {
int ch = getch();
//chgat(1, attr, clr, NULL);
switch (ch) {
case KEY_LEFT:
if (x > 0)
x--;
break;
case KEY_RIGHT:
if (x < 79)
x++;
break;
case KEY_UP:
if (y > 0)
y--;
break;
case KEY_DOWN:
if (y < HGT - 1)
y++;
break;
case KEY_HOME:
case KEY_STAB:
case KEY_BTAB:
case KEY_END:
case 'q':
goto cleanup;
default:
break;
}
addch(chr);
draw_status(y, x);
chr = mvinch(y,x); // save attr
clr = chr & A_COLOR;
attr = chr & A_ATTRIBUTES;
chgat(1, A_REVERSE | attr, 0, NULL);
refresh();
}
cleanup:
endwin();
return 0;
}
\ No newline at end of file
#ifndef PANE_H
#define PANE_H
#include <curses.h>
#include <stdint.h>
#include <malloc.h>
#include <string.h>
#include <stdbool.h>
#define LBL 0
#define BTN 1
#define RLR 2
#define INP 3
#define END 0b1111
typedef unsigned char byte;
typedef struct Field {
byte type : 4;
size_t y : 16
, x : 16
, len;
char* text;
chtype attr;
short nxfld;
void* (*callback)(char*);
} Field;
typedef struct Mask {
char type:4;
char padding:4;
short fldid;
}Mask;
typedef struct Screen {
Field* flds;
Field* inps;
Mask cell[80][43];
void (*submit)(char*);
}Screen;
extern int start();
void draw(Screen *scr);
#endif
\ No newline at end of file
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
!_TAG_PROGRAM_VERSION 0.0.0 /3fdf28bc/
$(PROJECT) Makefile /^$(PROJECT) : $(OBJ) | obj\/$/;" t
BTN src/pane.h /^#define BTN /;" d
CFLAGS Makefile /^CFLAGS = -std=gnu11 -Wall -fpic$/;" m
END src/pane.h /^#define END /;" d
Field src/pane.h /^typedef struct Field {$/;" s
Field src/pane.h /^} Field;$/;" t typeref:struct:Field
HEADERS Makefile /^HEADERS = $(wildcard src\/*.h)$/;" m
HGT src/pane.c /^#define HGT /;" d file:
INP src/pane.h /^#define INP /;" d
INPT src/pane.c /^#define INPT /;" d file:
LBL src/pane.h /^#define LBL /;" d
Mask src/pane.h /^typedef struct Mask {$/;" s
Mask src/pane.h /^}Mask;$/;" t typeref:struct:Mask
OBJ Makefile /^OBJ = $(addprefix obj\/,$(notdir $(SRC:.c=.o)))$/;" m
PANE_H src/pane.h /^#define PANE_H$/;" d
PROJECT Makefile /^PROJECT = icpl$/;" m
RLR src/pane.h /^#define RLR /;" d
SRC Makefile /^SRC = $(wildcard src\/*.c)$/;" m
Screen src/pane.h /^typedef struct Screen {$/;" s
Screen src/pane.h /^}Screen;$/;" t typeref:struct:Screen
TEXT src/pane.c /^#define TEXT(/;" d file:
TXTCMD src/pane.c /^#define TXTCMD /;" d file:
TXTHDR src/pane.c /^#define TXTHDR /;" d file:
TXTOPT src/pane.c /^#define TXTOPT /;" d file:
__anon7198f2f10108 src/pane.c /^struct {$/;" s file:
attr src/pane.h /^ chtype attr;$/;" m struct:Field typeref:typename:chtype
byte src/pane.h /^typedef unsigned char byte;$/;" t typeref:typename:unsigned char
callback src/pane.h /^ void* (*callback)(char*);$/;" m struct:Field typeref:typename:void * (*)(char *)
cell src/pane.h /^ Mask cell[80][43];$/;" m struct:Screen typeref:typename:Mask[80][43]
clean Makefile /^clean:$/;" t
debug Makefile /^debug: $(PROJECT)$/;" t
debug Makefile /^debug: CFLAGS += -g$/;" t
draw src/pane.c /^void draw(Screen *scr) {$/;" f typeref:typename:void
draw_status src/pane.c /^void draw_status(int y, int x) {$/;" f typeref:typename:void
fldid src/pane.h /^ short fldid;$/;" m struct:Mask typeref:typename:short
flds src/pane.h /^ Field* flds;$/;" m struct:Screen typeref:typename:Field *
inhibit src/pane.c /^ char inhibit[9];$/;" m struct:__anon7198f2f10108 typeref:typename:char[9] file:
init src/pane.c /^void init() {$/;" f typeref:typename:void
init_screen src/pane.c /^Screen* init_screen(Field *fields) {$/;" f typeref:typename:Screen *
inps src/pane.h /^ Field* inps;$/;" m struct:Screen typeref:typename:Field *
isInsert src/pane.c /^ bool isInsert;$/;" m struct:__anon7198f2f10108 typeref:typename:bool file:
len src/pane.h /^ , len;$/;" m struct:Field typeref:typename:size_t
main src/pane.c /^int main() {$/;" f typeref:typename:int
menuFlds src/pane.c /^Field menuFlds[] = {$/;" v typeref:typename:Field[]
nxfld src/pane.h /^ short nxfld;$/;" m struct:Field typeref:typename:short
obj/ Makefile /^obj\/:$/;" t
obj/%.o Makefile /^obj\/%.o : %.c $(HEADERS) | obj\/$/;" t
obj/%.o Makefile /^obj\/%.o : %.c %.h $(HEADERS) | obj\/$/;" t
padding src/pane.h /^ char padding:4;$/;" m struct:Mask typeref:typename:char:4
profile Makefile /^profile: $(PROJECT)$/;" t
profile Makefile /^profile: CFLAGS += -g -pg$/;" t
rebuild Makefile /^rebuild: clean release$/;" t
release Makefile /^release: $(PROJECT)$/;" t
release Makefile /^release: CFLAGS += -O3$/;" t
status src/pane.c /^}status = {$/;" v typeref:struct:__anon7198f2f10108
submit src/pane.h /^ void (*submit)(char*);$/;" m struct:Screen typeref:typename:void (*)(char *)
text src/pane.h /^ char* text;$/;" m struct:Field typeref:typename:char *
type src/pane.h /^ byte type : 4;$/;" m struct:Field typeref:typename:byte:4
type src/pane.h /^ char type:4;$/;" m struct:Mask typeref:typename:char:4
x src/pane.h /^ , x : 16$/;" m struct:Field typeref:typename:size_t:16
y src/pane.h /^ size_t y : 16$/;" m struct:Field typeref:typename:size_t:16
vpath %.c src
vpath %.h src
PROJECT = ispf
HEADERS = $(wildcard src/*.h)
SRC = $(wildcard src/*.c)
OBJ = $(addprefix obj/,$(notdir $(SRC:.c=.o)))
CFLAGS = -std=gnu11 -Wall
release: CFLAGS += -O3
release: $(PROJECT)
debug: CFLAGS += -g
debug: $(PROJECT)
profile: CFLAGS += -g -pg
profile: $(PROJECT)
rebuild: clean release
$(PROJECT) : $(OBJ) | obj/
$(CC) $(CFLAGS) -o $(PROJECT) $(OBJ) -L../icpl -licpl -Wl,-rpath=../icpl -lncurses
obj/%.o : %.c %.h $(HEADERS) | obj/
$(CC) $(CFLAGS) -o [email protected] -c $<
obj/%.o : %.c $(HEADERS) | obj/
$(CC) $(CFLAGS) -o [email protected] -c $<
obj/:
mkdir -p obj
clean:
rm -f $(PROJECT) $(OBJ)
#!/bin/bash
MAX=100
for ((n=2; n <= MAX; n+=2))
do
valgrind --tool=massif --stacks=yes --massif-out-file=massif.out.$n ../server -t2 -d1 -s1 -l20 -T12 4444 &
sleep 1
../../fastclient/fastclient localhost 4444 $n > /dev/null
sleep 1
#read -n 1 -s -r -p "Press any key to continue"
done
#!/bin/bash
MAX=100
mkdir -p prof
for ((n=2; n <= MAX; n+=2))
do
valgrind --tool=massif --stacks=yes --massif-out-file=./prof/massif.out.$n ./server -t2 -d1 -s1 -l20 -T12 4444 &
sleep 1
../fastclient/fastclient localhost 4444 $n > /dev/null
sleep 1
done
for f in prof/massif.out.*;do echo -n ${${f}##*.},; ms_print $f | grep -oE "(.*)\^" | tr -d '^';done | sort -n<Paste>
#include "../../icpl/src/pane.h"
int main() {
start();
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment