<commit_before>/*
 ============================================================================
 Name        : opcuaServer.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description :
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>



#include "../../src/opcua_binaryEncDec.h"
#include "../../src/opcua_builtInDatatypes.h"
#include "../../src/opcua_transportLayer.h"
#include "../../src/opcua_types.h"

#ifdef LINUX

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/socketvar.h>

void server_init();
void server_run();

#endif
#define PORT    16664
     #define MAXMSG  512
int main(void)
{

#ifdef LINUX
	server_init();
	server_run();
#endif

	return EXIT_SUCCESS;

}

#ifdef LINUX

void server_init()
{
	puts("starting demo Server");
	//call listen

}
void server_run()
{
	UA_connection connection;
	UA_ByteString slMessage;
	TL_initConnectionObject(&connection);
	char optval;
	int sockfd, newsockfd, portno, clilen;
	char buffer[8192];
	struct sockaddr_in serv_addr, cli_addr;
	int  n;

	/* First call to socket() function */
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd < 0)
	{
		perror("ERROR opening socket");
		exit(1);
	}

	/* Initialize socket structure */
	bzero((char *) &serv_addr, sizeof(serv_addr));
	portno = 16664;
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_addr.s_addr = INADDR_ANY;
	serv_addr.sin_port = htons(portno);
	optval = 1;

	if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(int)) == -1) {
	    perror("setsockopt");
	    exit(1);
	}
	/* Now bind the host address using bind() call.*/
	if (bind(sockfd, (struct sockaddr *) &serv_addr,
						  sizeof(serv_addr)) < 0)
	{
		 perror("ERROR on binding");
		 exit(1);
	}

	/* Now start listening for the clients, here process will
	* go in sleep mode and will wait for the incoming connection
	*/
	listen(sockfd,5);
	clilen = sizeof(cli_addr);

	/* Accept actual connection from the client */
	newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,
								&clilen);
	if (newsockfd < 0)
	{
		perror("ERROR on accept");
		exit(1);
	}
	printf("One connection accepted");
	while(1)
	{
		/* If connection is established then start communicating */
		bzero(buffer,8192);

		n = read( newsockfd,buffer,8192);

		if (n > 0)
		{
			printf("received: %s\n",buffer);
			connection.readData.Data = buffer;
			connection.readData.Length = n;
			connection.newDataToRead = 1;

			//TL_receive(&connection, &slMessage);
			SL_receive(&connection, &slMessage);
		}
		else if (n < 0)
		{
			perror("ERROR reading from socket1");
			exit(1);
		}

		if(connection.newDataToWrite)
		{
			printf("data will be sent \n");<commit_msg>put magic numbers into preprocessor defines<commit_after>/*
 ============================================================================
 Name        : opcuaServer.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description :
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>



#include "../../src/opcua_binaryEncDec.h"
#include "../../src/opcua_builtInDatatypes.h"
#include "../../src/opcua_transportLayer.h"
#include "../../src/opcua_types.h"

#ifdef LINUX

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/socketvar.h>

void server_init();
void server_run();

#endif

#define PORT    16664
#define MAXMSG  512
#define BUFFER_SIZE 8192

int main(void)
{

#ifdef LINUX
	server_init();
	server_run();
#endif

	return EXIT_SUCCESS;

}

#ifdef LINUX

void server_init()
{
	puts("starting demo Server");
	//call listen

}

void server_run()
{
	UA_connection connection;
	UA_ByteString slMessage;
	TL_initConnectionObject(&connection);
	char optval;
	int sockfd, newsockfd, portno, clilen;
	char buffer[BUFFER_SIZE];
	struct sockaddr_in serv_addr, cli_addr;
	int  n;

	/* First call to socket() function */
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd < 0)
	{
		perror("ERROR opening socket");
		exit(1);
	}

	/* Initialize socket structure */
	bzero((char *) &serv_addr, sizeof(serv_addr));
	portno = PORT;
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_addr.s_addr = INADDR_ANY;
	serv_addr.sin_port = htons(portno);
	optval = 1;

	if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(int)) == -1) {
	    perror("setsockopt");
	    exit(1);
	}
	/* Now bind the host address using bind() call.*/
	if (bind(sockfd, (struct sockaddr *) &serv_addr,
						  sizeof(serv_addr)) < 0)
	{
		 perror("ERROR on binding");
		 exit(1);
	}

	/* Now start listening for the clients, here process will
	* go in sleep mode and will wait for the incoming connection
	*/
	listen(sockfd,5);
	clilen = sizeof(cli_addr);

	/* Accept actual connection from the client */
	newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,
								&clilen);
	if (newsockfd < 0)
	{
		perror("ERROR on accept");
		exit(1);
	}
	printf("One connection accepted");
	while(1)
	{
		/* If connection is established then start communicating */
		bzero(buffer,BUFFER_SIZE);

		n = read( newsockfd,buffer,BUFFER_SIZE);

		if (n > 0)
		{
			printf("received: %s\n",buffer);
			connection.readData.Data = buffer;
			connection.readData.Length = n;
			connection.newDataToRead = 1;

			//TL_receive(&connection, &slMessage);
			SL_receive(&connection, &slMessage);
		}
		else if (n < 0)
		{
			perror("ERROR reading from socket1");
			exit(1);
		}

		if(connection.newDataToWrite)
		{
			printf("data will be sent \n");
{'fraction_non_alphanumeric': 0.18957771787960467, 'fraction_numerical': 0.012758310871518418, 'mean_word_length': 4.018935978358882, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5687895', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1917, 'n_words': 459}