aman: developing a lightweight, hi-performance and dynamic json api server with c

11
Developing a lightweight, hi-performance and dynamic JSON api server with C Shaikh Sonny Aman for SQABD LT4

Upload: sqabd

Post on 22-Apr-2015

815 views

Category:

Documents


1 download

DESCRIPTION

SQABD Lightning Talks 4 www.sqabd.com

TRANSCRIPT

Page 1: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Developing a lightweight, hi-performance and dynamic JSON

api server with C

Shaikh Sonny Aman for

SQABD LT4

Page 2: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Background

Page 3: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Play Tools

PHP Java Python C

Page 4: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

WHY!!

Page 5: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Requirement

http://myserver.com:8080?mod=score&action=get_score&id=123

{score:4,id:123

}

Page 6: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

The Server

if ( (client_socket=accept(server_socket, (struct sockaddr *)&cad, &alen)) < 0) {

printf("accept failed\n");exit (1);

}pthread_create(&tid, NULL, serverthread, (void*)client_socket );

While(1){

}

accept connection from clientrun a thread to process

Page 7: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Processing Request

Read all available data

recv(client_socket, buffer,buffer_size, 0);

Page 8: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Processing Request

Host: www.http.header.free.frAccept: image/gif, image/x-xbitmap, image/jpeg, imagepjpeg,Accept-Language: FrAccept-Encoding: gzip, deflate

Get the request params

mod=score&action=get_score&id=123GET: Http1.1

Page 9: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Calling Dynamic Function

PIC : Position Independent Code

dlopen(PATH, mode)

dlsym(handle, fun_name)

void (*fn)(int* cs,cJSON** js);

void echo_name(int* client_socket, cJSON** request)

Page 10: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

Demo

QuickTime™ and aH.264 decompressor

are needed to see this picture.

Page 11: Aman: Developing a lightweight, hi-performance and dynamic JSON api server with C

QnA