Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stunserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Stunserver
Commits
c77eedd4
Commit
c77eedd4
authored
Jan 10, 2012
by
John Selbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First stable TCP commit
parent
50059b0d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
180 additions
and
0 deletions
+180
-0
server/stunconnection.cpp
server/stunconnection.cpp
+94
-0
server/stunconnection.h
server/stunconnection.h
+57
-0
server/xxdperl.pl
server/xxdperl.pl
+29
-0
No files found.
server/stunconnection.cpp
0 → 100644
View file @
c77eedd4
#include "commonincludes.h"
#include "stuncore.h"
#include "stunconnection.h"
CConnectionPool
::
CConnectionPool
()
:
_freelist
(
NULL
)
{
}
CConnectionPool
::~
CConnectionPool
()
{
Reset
();
}
void
CConnectionPool
::
Reset
()
{
StunConnection
*
pConn
;
while
(
_freelist
)
{
pConn
=
_freelist
;
_freelist
=
_freelist
->
pNext
;
delete
pConn
;
}
}
HRESULT
CConnectionPool
::
Grow
()
{
const
size_t
c_growrate
=
50
;
for
(
size_t
i
=
0
;
i
<
c_growrate
;
i
++
)
{
StunConnection
*
pConn
=
NULL
;
pConn
=
new
StunConnection
();
if
(
pConn
==
NULL
)
{
return
E_OUTOFMEMORY
;
}
pConn
->
_spOutputBuffer
=
CRefCountedBuffer
(
new
CBuffer
(
MAX_STUN_MESSAGE_SIZE
));
pConn
->
_spReaderBuffer
=
CRefCountedBuffer
(
new
CBuffer
(
MAX_STUN_MESSAGE_SIZE
));
if
((
pConn
->
_spOutputBuffer
==
NULL
)
||
(
pConn
->
_spReaderBuffer
==
NULL
))
{
delete
pConn
;
return
E_OUTOFMEMORY
;
}
pConn
->
pNext
=
_freelist
;
_freelist
=
pConn
;
}
return
S_OK
;
}
StunConnection
*
CConnectionPool
::
GetConnection
(
int
sock
,
SocketRole
role
)
{
StunConnection
*
pConn
=
NULL
;
if
(
_freelist
==
NULL
)
{
Grow
();
if
(
_freelist
==
NULL
)
{
return
NULL
;
// out of memory ?
}
}
pConn
=
_freelist
;
_freelist
=
pConn
->
pNext
;
pConn
->
pNext
=
NULL
;
// prep this connection for usage
pConn
->
_reader
.
Reset
();
pConn
->
_reader
.
GetStream
().
Attach
(
pConn
->
_spReaderBuffer
,
true
);
pConn
->
_state
=
ConnectionState_Receiving
;
pConn
->
_stunsocket
.
Attach
(
sock
);
pConn
->
_stunsocket
.
SetRole
(
role
);
pConn
->
_txCount
=
0
;
pConn
->
_timeStart
=
time
(
NULL
);
pConn
->
_idHashTable
=
-
1
;
return
pConn
;
}
void
CConnectionPool
::
ReleaseConnection
(
StunConnection
*
pConn
)
{
ASSERT
(
pConn
->
_stunsocket
.
IsValid
()
==
false
);
// not the pool's job to close a socket!
pConn
->
pNext
=
_freelist
;
_freelist
=
pConn
;
}
server/stunconnection.h
0 → 100644
View file @
c77eedd4
#ifndef STUN_CONNECTION_H
#define STUN_CONNECTION_H
#include "stuncore.h"
#include "stunsocket.h"
enum
StunConnectionState
{
ConnectionState_Idle
,
ConnectionState_Receiving
,
ConnectionState_Transmitting
,
ConnectionState_Closing
,
// shutdown has been called, waiting for close notification on other end
};
struct
StunConnection
{
time_t
_timeStart
;
StunConnectionState
_state
;
CStunSocket
_stunsocket
;
CStunMessageReader
_reader
;
CRefCountedBuffer
_spReaderBuffer
;
CRefCountedBuffer
_spOutputBuffer
;
// contains the response
size_t
_txCount
;
// number of bytes of response transmitted thus far
int
_idHashTable
;
// hints at which hash table the connection got inserted into
StunConnection
*
pNext
;
// next item in pool - meaningless outside of the pool
};
class
CConnectionPool
{
private:
StunConnection
*
_freelist
;
HRESULT
Grow
();
public:
CConnectionPool
();
~
CConnectionPool
();
StunConnection
*
GetConnection
(
int
sock
,
SocketRole
role
);
void
ReleaseConnection
(
StunConnection
*
pConn
);
void
Reset
();
};
#endif
\ No newline at end of file
server/xxdperl.pl
0 → 100644
View file @
c77eedd4
#!/usr/bin/perl
# xxdperl.pl
# emulates "xxd -i" in perl (stdin and stdout only)
$count
=
0
;
while
(
$input
=
<
STDIN
>
)
{
@characters
=
split
(
//
,
$input
);
foreach
(
@characters
)
{
if
(
$count
!=
0
)
{
print
'
,
';
if
((
$count
%
12
)
==
0
)
{
print
"
\n
";
}
}
else
{
print
'
';
}
print
sprintf
("
0x%.2x
",
ord
(
$_
));
$count
++
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment