-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSCTPServerGSocket.cpp
executable file
·66 lines (57 loc) · 2.33 KB
/
SCTPServerGSocket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: SCTPServerGSocket.cpp
* Author: gedas
*
* Created on Antradienis, 2016, balandis 12, 04.54
*/
#include "SCTPServerGSocket.h"
#include "SCTPClientGSocket.h"
GServer::SCTPServerGSocket::SCTPServerGSocket(GServer::GConfig* conf,
GLogger* logger, fd_set& visiSocket, int& maxDeskriptor,
GCommandExecution* command) : SCTPGSocket(conf, logger, command) {
// Nustatau pavadinima
this->className = this->className + ":SCTPServerGSocket";
// Objektui reikalingi veiksmai
// Sukuriu socketa klausimuisi
this->createServerScoket(
const_cast<char*> (conf->getStringSetting("IP").c_str()),
const_cast<char*> (conf->getStringSetting("PORT").c_str()),
conf->getIntSetting("NETWORK_TYPE"), SOCK_STREAM, IPPROTO_SCTP,
AI_PASSIVE);
// Nustatau skaitomu socketu sarasa
this->skaitomiSocket = &visiSocket;
// Pridedu socketa i socketu sarasa
FD_SET(this->socket_descriptor, this->skaitomiSocket);
// Tikrinu ar nera didenis deskritprious nei dabartinis
this->checkMaxDescriptor(maxDeskriptor);
// Objektas sukurtas pilnai
this->logger->logDebug(this->className, "Objektas sukurtas");
}
GServer::SCTPServerGSocket::~SCTPServerGSocket() {
// Naikinimas
this->logger->logDebug(this->className, "Baigiu darba su " +
std::to_string(this->socket_descriptor) + " socketu");
this->close();
this->logger->logDebug(this->className, "Pasalinu is skaitomu saraso");
FD_CLR(this->socket_descriptor, this->skaitomiSocket);
// Objektas sunaikintas
this->logger->logDebug(this->className, "Objektas sunaikintas");
}
GServer::GSocket* GServer::SCTPServerGSocket::acceptConnection(
GServer::GConfig* conf, int &maxDescriptor){
GServer::GSocket* returnValue = NULL;
// Gaunu deskriptoriu
int descriptor = acceptConnectionDescriptor();
// Jei pavyko gauti deskriptoriu
if( descriptor > 0 ){
// Pavyko gauti, kuriam nauja objekta
returnValue = new GServer::SCTPClientGSocket(descriptor, conf,
this->logger, this->skaitomiSocket, maxDescriptor, this->commands);
}
return returnValue;
}