parent
14240512e5
commit
929e257a8e
@ -1,5 +1,8 @@
|
||||
#ifndef FUNCTIONS
|
||||
#define FUNCTIONS
|
||||
#include "../includes/include.h"
|
||||
|
||||
node_info *create_function(char *pName, node_info *pStmts);
|
||||
node_info *create_function_call(char *pName);
|
||||
node_info *create_compound_statement(node_info *new_statement_list, node_info *statement_head);
|
||||
node_info *create_compound_statement(node_info *new_statement_list, node_info *statement_head);
|
||||
#endif
|
@ -1,4 +1,7 @@
|
||||
#ifndef LINKED_LIST_H
|
||||
#define LINKED_LIST_H
|
||||
#include "../includes/include.h"
|
||||
|
||||
void _free_linked_list(node_info *pList);
|
||||
node_info *copy_linked_list(node_info *pList);
|
||||
node_info *copy_linked_list(node_info *pList);
|
||||
#endif
|
@ -1 +1,6 @@
|
||||
node_info *createLogic(int opperation, int expr, node_info *statement_list, node_info *else_false);
|
||||
#ifndef LOGIC_H
|
||||
#define LOGIC_H
|
||||
|
||||
node_info *createLogic(int opperation, int expr, node_info *statement_list, node_info *else_false);
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include "socket.h"
|
||||
|
||||
int main() {
|
||||
|
||||
Socket news = create_lsocket(5001, 5);
|
||||
|
||||
printf("Created socket!\n");
|
||||
sleep(10);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdlib.h>
|
||||
#include <netinet/in.h>
|
||||
#include <strings.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* socket struct for building sockets...
|
||||
* This will hold both listening sockets and connection sockets
|
||||
* TCP AND UDP!
|
||||
*
|
||||
*/
|
||||
typedef struct Socket {
|
||||
|
||||
int socketfd; //socket id
|
||||
int client_socketfd; // this is the int you get when you call accept()
|
||||
int port; // port information
|
||||
struct sockaddr_in address; // sockaddr_in struct
|
||||
struct Socket *next; // next in the linked list
|
||||
|
||||
} Socket;
|
||||
//head of the linked list of sockets
|
||||
struct Socket *_socket_head = NULL;
|
||||
/**
|
||||
* This is used by a thread to listen for incoming
|
||||
* connections
|
||||
*
|
||||
*/
|
||||
|
||||
void doprocessing (int sock) {
|
||||
int n;
|
||||
char buffer[256];
|
||||
bzero(buffer,256);
|
||||
while(1) {
|
||||
n = read(sock,buffer,255);
|
||||
|
||||
if (n < 0) {
|
||||
perror("ERROR reading from socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("Here is the message: %s\n",buffer);
|
||||
n = write(sock,"I got your message",18);
|
||||
|
||||
if (n < 0) {
|
||||
perror("ERROR writing to socket");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This function creates a listening function...
|
||||
* @params takes a an int for a port.
|
||||
* @return An active listening socket for incoming connections
|
||||
*
|
||||
*/
|
||||
Socket create_lsocket(int _port, int _connection_amount) {
|
||||
|
||||
Socket *newSocket = malloc(sizeof(Socket));
|
||||
|
||||
//sockaddr_in struct stuff (making a new sockaddr_in and giving it details)
|
||||
struct sockaddr_in address; // make a struct of type sockaddr_in
|
||||
int addr_size = sizeof(address); // size of addess in decimal form
|
||||
|
||||
// filling our struct with info
|
||||
address.sin_family = AF_INET; //ipv4....
|
||||
address.sin_addr.s_addr = INADDR_ANY; // any local address I.E :0.0.0.0
|
||||
address.sin_port = htons(_port); // htons takes a decimal number and converts it to network
|
||||
|
||||
|
||||
//this is a socket handler, like a file handler...
|
||||
int socketfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
// if the socks returns 0 then exit
|
||||
if (socketfd == 0) {
|
||||
|
||||
printf("SOCKET FAILED!\n");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
//lets bind that socket now
|
||||
int bindRes = bind(socketfd, (struct sockaddr *)&address, sizeof(address));
|
||||
if(bindRes < 0) {
|
||||
|
||||
printf("BIND FAILED! WITH CODE: %d\n", bindRes);
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
listen(socketfd, 5);
|
||||
while(1) {
|
||||
|
||||
int newsockfd = accept(socketfd, (struct sockaddr *) &address, &addr_size);
|
||||
|
||||
if (newsockfd < 0) {
|
||||
|
||||
printf("ERROR LISTENING!\n");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
int pid = fork();
|
||||
if (pid == 0) {
|
||||
|
||||
printf("NEW CLIENT!\n");
|
||||
doprocessing(newsockfd);
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
newSocket->socketfd = socketfd;
|
||||
newSocket->port = _port;
|
||||
newSocket->address = address;
|
||||
newSocket->next = NULL;
|
||||
// if the socket head is empty we are going to malloc the head and then start
|
||||
// the linked list of sockets
|
||||
if (_socket_head == NULL) {
|
||||
|
||||
_socket_head = malloc(sizeof(Socket));
|
||||
_socket_head->next = newSocket;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
socket = l_SOCKET("0.0.0.0", 90); //creates a server socket
|
||||
client = C_SOCKET("127.0.0.1", 90); // creates a client
|
||||
socket.template = {
|
||||
|
||||
"HEADER-DATA" : varToSaveData : call responce;,
|
||||
"SOMEOTHER-HEADER" : varToSaveData : call responce;
|
||||
|
||||
}
|
||||
|
||||
|
||||
client.plan = {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdlib.h>
|
||||
#include <netinet/in.h>
|
||||
#include <strings.h>
|
||||
|
||||
|
||||
void doprocessing (int sock) {
|
||||
int n;
|
||||
char buffer[256];
|
||||
bzero(buffer,256);
|
||||
while(1) {
|
||||
n = read(sock,buffer,255);
|
||||
|
||||
if (n < 0) {
|
||||
perror("ERROR reading from socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("Here is the message: %s\n",buffer);
|
||||
n = write(sock,"I got your message",18);
|
||||
|
||||
if (n < 0) {
|
||||
perror("ERROR writing to socket");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int port = 5001;
|
||||
struct sockaddr_in address;
|
||||
int clilen = sizeof(address);
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
address.sin_port = htons(port);
|
||||
|
||||
int socketHandler = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (socketHandler == 0) {
|
||||
|
||||
printf("SOCKET FAILED!\n");
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
|
||||
printf("SETUP SOCKET!\n");
|
||||
}
|
||||
int bindRes = bind(socketHandler, (struct sockaddr *)&address, sizeof(address));
|
||||
if(bindRes < 0) {
|
||||
|
||||
printf("BIND FAILED! CODE: %d\n", bindRes);
|
||||
|
||||
} else {
|
||||
|
||||
printf("BINDED SOCKET!\n");
|
||||
|
||||
}
|
||||
listen(socketHandler, 5);
|
||||
while(1) {
|
||||
|
||||
int newsockfd = accept(socketHandler, (struct sockaddr *) &address, &clilen);
|
||||
|
||||
if (newsockfd < 0) {
|
||||
|
||||
printf("ERROR LISTENING!\n");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
int pid = fork();
|
||||
if (pid == 0) {
|
||||
|
||||
printf("NEW CLIENT!\n");
|
||||
doprocessing(newsockfd);
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,2 +1,5 @@
|
||||
#ifndef PRINT_H
|
||||
#define PRINT_H
|
||||
node_info *create_print_var_node(char *pVarName);
|
||||
node_info *create_print_statement(int opperation, int value, char *string);
|
||||
node_info *create_print_statement(int opperation, int value, char *string);
|
||||
#endif
|
@ -1,6 +1,9 @@
|
||||
#ifndef VARS_H
|
||||
#define VARS_H
|
||||
void add_var(char *name, variable_values *values, map_void_t* pVarMap);
|
||||
variable_values *get_value(char *pName, map_void_t* pVarMap);
|
||||
variable* make_variable_int(char *pName, int value);
|
||||
variable* make_variable_double(char *pName, double value);
|
||||
variable* make_variable_char(char *pName, char value);
|
||||
variable* make_variable_string(char *pName, char *value);
|
||||
variable* make_variable_string(char *pName, char *value);
|
||||
#endif
|
Loading…
Reference in new issue