|
@@ -10,11 +10,14 @@
|
|
|
#include <netinet/in.h>
|
|
|
#include <sys/socketvar.h>
|
|
|
|
|
|
+#include <unistd.h> // read, write, close
|
|
|
#include <errno.h> // errno, EINTR
|
|
|
|
|
|
+#include <memory.h> // memset
|
|
|
#include <pthread.h>
|
|
|
|
|
|
#include "UA_stack.h"
|
|
|
+#include "opcua_transportLayer.h"
|
|
|
|
|
|
UA_TL_Description UA_TransportLayerDescriptorTcpBinary = {
|
|
|
UA_TL_ENCODING_BINARY,
|
|
@@ -27,26 +30,13 @@ UA_TL_Description UA_TransportLayerDescriptorTcpBinary = {
|
|
|
UA_TL_data theTL;
|
|
|
|
|
|
|
|
|
-/** checks arguments and dispatches to worker or refuses to init */
|
|
|
-UA_Int32 UA_TL_init(UA_TL_Description* tlDesc, UA_Int32 port) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if (tlDesc->connectionType == UA_TL_CONNECTIONTYPE_TCPV4 && tlDesc->encoding == UA_TL_ENCODING_BINARY) {
|
|
|
- theTL.tld = &tlDesc;
|
|
|
- UA_list_init(&theTL.connections);
|
|
|
- retval |= UA_TL_TCP_init(theTL,port);
|
|
|
- } else {
|
|
|
- retval = UA_ERR_NOT_IMPLEMENTED;
|
|
|
- }
|
|
|
- return retval;
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
/** the tcp reader thread **/
|
|
|
void* UA_TL_TCP_reader(void *p) {
|
|
|
UA_TL_connection* c = (UA_TL_connection*) p;
|
|
|
|
|
|
UA_ByteString readBuffer;
|
|
|
- UA_alloc(&(readBuffer.data),c->localConf.recvBufferSize);
|
|
|
+ UA_alloc((void**)&(readBuffer.data),c->localConf.recvBufferSize);
|
|
|
|
|
|
while (c->connectionState != connectionState_CLOSE) {
|
|
|
readBuffer.length = read(c->socket, readBuffer.data, c->localConf.recvBufferSize);
|
|
@@ -54,7 +44,7 @@ void* UA_TL_TCP_reader(void *p) {
|
|
|
UA_ByteString_printx("server_run - received=",&readBuffer);
|
|
|
|
|
|
if (readBuffer.length > 0) {
|
|
|
- TL_process(&c,&readBuffer);
|
|
|
+ TL_process(c,&readBuffer);
|
|
|
} else if (readBuffer.length < 0) {
|
|
|
perror("ERROR reading from socket1");
|
|
|
break;
|
|
@@ -104,15 +94,15 @@ void* UA_TL_TCP_listen(void *p) {
|
|
|
// accept only if not max number of connections exceeded
|
|
|
if (tld->tld->maxConnections == -1 || tld->connections.size < tld->tld->maxConnections) {
|
|
|
struct sockaddr_in cli_addr;
|
|
|
- int cli_len = sizeof(cli_addr);
|
|
|
+ socklen_t cli_len = sizeof(cli_addr);
|
|
|
int newsockfd = accept(tld->listenerHandle, (struct sockaddr *) &cli_addr, &cli_len);
|
|
|
if (newsockfd < 0) {
|
|
|
perror("ERROR on accept");
|
|
|
} else {
|
|
|
UA_TL_connection* c;
|
|
|
UA_Int32 retval = UA_SUCCESS;
|
|
|
- retval |= UA_alloc(&c,sizeof(UA_TL_connection));
|
|
|
- TL_Connection_init(c, tld);
|
|
|
+ retval |= UA_alloc((void**)&c,sizeof(UA_TL_connection));
|
|
|
+ TL_Connection_init(c, tld->tld);
|
|
|
c->socket = newsockfd;
|
|
|
c->UA_TL_writer = UA_TL_TCP_write;
|
|
|
// add to list
|
|
@@ -130,7 +120,6 @@ void* UA_TL_TCP_listen(void *p) {
|
|
|
UA_Int32 UA_TL_TCP_init(UA_TL_data* tld, UA_Int32 port) {
|
|
|
UA_Int32 retval = UA_SUCCESS;
|
|
|
// socket variables
|
|
|
- int sockfd;
|
|
|
int optval = 1;
|
|
|
struct sockaddr_in serv_addr;
|
|
|
|
|
@@ -151,12 +140,13 @@ UA_Int32 UA_TL_TCP_init(UA_TL_data* tld, UA_Int32 port) {
|
|
|
retval = UA_ERROR;
|
|
|
} else {
|
|
|
// bind to port
|
|
|
- if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
|
|
|
+ if (bind(tld->listenerHandle, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
|
|
|
perror("ERROR on binding");
|
|
|
retval = UA_ERROR;
|
|
|
} else {
|
|
|
// TODO: implement
|
|
|
// UA_String_sprintf("opc.tpc://localhost:%d", &(tld->endpointUrl), port);
|
|
|
+ UA_String_copycstring("opc.tpc://localhost:16664/", &(tld->endpointUrl));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -168,6 +158,19 @@ UA_Int32 UA_TL_TCP_init(UA_TL_data* tld, UA_Int32 port) {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
+/** checks arguments and dispatches to worker or refuses to init */
|
|
|
+UA_Int32 UA_TL_init(UA_TL_Description* tlDesc, UA_Int32 port) {
|
|
|
+ UA_Int32 retval = UA_SUCCESS;
|
|
|
+ if (tlDesc->connectionType == UA_TL_CONNECTIONTYPE_TCPV4 && tlDesc->encoding == UA_TL_ENCODING_BINARY) {
|
|
|
+ theTL.tld = tlDesc;
|
|
|
+ UA_list_init(&theTL.connections);
|
|
|
+ retval |= UA_TL_TCP_init(&theTL,port);
|
|
|
+ } else {
|
|
|
+ retval = UA_ERR_NOT_IMPLEMENTED;
|
|
|
+ }
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
/** checks arguments and dispatches to worker or refuses to init */
|
|
|
UA_Int32 UA_Stack_init(UA_TL_Description* tlDesc, UA_Int32 port) {
|
|
|
UA_Int32 retval = UA_SUCCESS;
|