Skip to content

Commit 6e9c607

Browse files
committed
Initial import.
0 parents  commit 6e9c607

18 files changed

+1054
-0
lines changed

AMBuildScript

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# vim: set ts=2 sw=2 tw=99 et ft=python:
2+
#
3+
# Copyright (C) 2004-2012 David Anderson
4+
#
5+
# This file is part of SourcePawn.
6+
#
7+
# SourcePawn is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU General Public License as published by the Free
9+
# Software Foundation, either version 3 of the License, or (at your option)
10+
# any later version.
11+
#
12+
# SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License along with
17+
# SourcePawn. If not, see http://www.gnu.org/licenses/.
18+
#
19+
import os
20+
import sys
21+
22+
def Normalize(path):
23+
return os.path.abspath(os.path.normpath(path))
24+
25+
class KEConfig:
26+
def __init__(self):
27+
cfg = builder.DetectCompilers()
28+
cxx = cfg.cxx
29+
30+
if cxx.behavior is 'gcc':
31+
cfg.cflags += [
32+
'-pipe',
33+
'-Wall',
34+
'-Werror',
35+
'-Wno-switch',
36+
]
37+
cfg.cxxflags += ['-std=c++11']
38+
39+
have_gcc = cxx.name is 'gcc'
40+
have_clang = cxx.name is 'clang'
41+
if have_clang or (have_gcc and cxx.majorVersion >= 4):
42+
cfg.cflags += ['-fvisibility=hidden']
43+
cfg.cxxflags += ['-fvisibility-inlines-hidden']
44+
if have_clang or (have_gcc and cxx.minorVersion >= 6):
45+
cfg.cflags += ['-Wno-narrowing']
46+
if (have_gcc and cxx.minorVersion >= 7) or (have_clang and cxx.majorVersion >= 4):
47+
cfg.cxxflags += ['-Wno-delete-non-virtual-dtor']
48+
49+
cfg.cxxflags += [
50+
'-fno-exceptions',
51+
'-fno-threadsafe-statics',
52+
'-Wno-non-virtual-dtor',
53+
'-Wno-overloaded-virtual',
54+
'-Wno-unused-private-field',
55+
]
56+
57+
if have_gcc:
58+
cfg.cflags += ['-mfpmath=sse']
59+
60+
# Disable some stuff we don't use, that gives us better binary
61+
# compatibility on Linux.
62+
cfg.cxxflags += [
63+
'-fno-exceptions',
64+
'-fno-rtti',
65+
'-fno-threadsafe-statics',
66+
'-Wno-non-virtual-dtor',
67+
'-Wno-overloaded-virtual',
68+
'-Wno-invalid-offsetof',
69+
]
70+
71+
if (have_gcc and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
72+
(have_clang and cxx.majorVersion >= 3):
73+
cfg.cxxflags += ['-Wno-delete-non-virtual-dtor']
74+
75+
cfg.postlink += ['-lm']
76+
elif cxx.name is 'msvc':
77+
if builder.options.debug == '1':
78+
cfg.cflags += ['/MTd']
79+
cfg.linkflags += ['/NODEFAULTLIB:libcmt']
80+
else:
81+
cfg.cflags += ['/MT']
82+
cfg.defines += [
83+
'_CRT_SECURE_NO_DEPRECATE',
84+
'_CRT_SECURE_NO_WARNINGS',
85+
'_CRT_NONSTDC_NO_DEPRECATE',
86+
'_ITERATOR_DEBUG_LEVEL=0',
87+
]
88+
cfg.cflags += [
89+
'/W3',
90+
]
91+
cfg.cxxflags += [
92+
'/EHsc',
93+
'/GR-',
94+
'/TP',
95+
]
96+
cfg.linkflags += [
97+
'/MACHINE:X86',
98+
'/SUBSYSTEM:WINDOWS',
99+
'kernel32.lib',
100+
'user32.lib',
101+
'gdi32.lib',
102+
'winspool.lib',
103+
'comdlg32.lib',
104+
'advapi32.lib',
105+
'shell32.lib',
106+
'ole32.lib',
107+
'oleaut32.lib',
108+
'uuid.lib',
109+
'odbc32.lib',
110+
'odbccp32.lib',
111+
]
112+
113+
# Optimization
114+
if builder.options.opt == '1':
115+
cfg.defines += ['NDEBUG']
116+
if cxx.behavior == 'gcc':
117+
cfg.cflags += ['-O3']
118+
elif cxx.behavior == 'msvc':
119+
cfg.cflags += ['/Ox']
120+
cfg.linkflags += ['/OPT:ICF', '/OPT:REF']
121+
122+
# Debugging
123+
if builder.options.debug == '1':
124+
cfg.defines += ['DEBUG', '_DEBUG']
125+
if cxx.behavior == 'msvc':
126+
cfg.cflags += ['/Od', '/RTC1']
127+
128+
# This needs to be after our optimization flags which could otherwise disable it.
129+
if cxx.name == 'msvc':
130+
# Don't omit the frame pointer.
131+
cfg.cflags += ['/Oy-']
132+
133+
# Platform-specifics
134+
if builder.target_platform == 'linux':
135+
if cxx.name == 'gcc':
136+
cfg.linkflags += ['-static-libgcc']
137+
elif cxx.name == 'clang':
138+
cfg.linkflags += ['-lgcc_eh']
139+
cfg.linkflags += ['-lpthread', '-lrt']
140+
elif builder.target_platform == 'mac':
141+
cfg.linkflags += [
142+
'-mmacosx-version-min=10.5',
143+
]
144+
elif builder.target_platform == 'windows':
145+
cfg.defines += ['WIN32', '_WINDOWS']
146+
147+
cfg.defines += ['KE_THREADSAFE']
148+
149+
if builder.options.amtl:
150+
amtl_path = Normalize(builder.options.amtl)
151+
if not os.path.isdir(amtl_path):
152+
raise Exception('Could not find AMTL at: {0}'.format(amtl_path))
153+
cfg.cxxincludes += [os.path.join(amtl_path, 'include')]
154+
cfg.cxxincludes += [
155+
os.path.join(builder.sourcePath, 'include'),
156+
]
157+
158+
KE = KEConfig()
159+
160+
builder.RunScript('static_lib.ambuild', { 'KE': KE })
161+

configure.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# vim: set ts=2 sw=2 tw=99 noet ft=python:
2+
#
3+
# Copyright (C) 2004-2012 David Anderson
4+
#
5+
# This file is part of SourcePawn.
6+
#
7+
# SourcePawn is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU General Public License as published by the Free
9+
# Software Foundation, either version 3 of the License, or (at your option)
10+
# any later version.
11+
#
12+
# SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License along with
17+
# SourcePawn. If not, see http://www.gnu.org/licenses/.
18+
#
19+
import sys
20+
try:
21+
from ambuild2 import run
22+
except:
23+
try:
24+
import ambuild
25+
sys.stderr.write('It looks like you have AMBuild 1 installed, but this project uses AMBuild 2.\n')
26+
sys.stderr.write('Upgrade to the latest version of AMBuild to continue.\n')
27+
except:
28+
sys.stderr.write('AMBuild must be installed to build this project.\n')
29+
sys.stderr.write('http://www.alliedmods.net/ambuild\n')
30+
sys.exit(1)
31+
32+
run = run.PrepareBuild(sourcePath=sys.path[0])
33+
run.options.add_option('--enable-debug', action='store_const', const='1', dest='debug',
34+
help='Enable debugging symbols')
35+
run.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
36+
help='Enable optimization')
37+
run.options.add_option('--arch', dest='arch', help='Architecture (x86, x64)')
38+
run.options.add_option('--amtl', type='string', dest='amtl', help='AMTL path')
39+
run.Configure()

include/amio-types.h

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// vim: set ts=2 sw=2 tw=99 et:
2+
//
3+
// Copyright (C) 2014 David Anderson
4+
//
5+
// This file is part of the AlliedModders I/O Library.
6+
//
7+
// The AlliedModders I/O library is licensed under the GNU General Public
8+
// License, version 3 or higher. For more information, see LICENSE.txt
9+
//
10+
#ifndef _include_amio_types_h_
11+
#define _include_amio_types_h_
12+
13+
#include <am-refcounting.h>
14+
15+
namespace amio {
16+
17+
// Types of errors that can occur.
18+
enum class ErrorType
19+
{
20+
// System error.
21+
System,
22+
23+
// Library error.
24+
Library,
25+
26+
// Generic I/O exception.
27+
Exception
28+
};
29+
30+
// Represents an I/O error.
31+
class IOError : public ke::Refcounted<IOError>
32+
{
33+
public:
34+
// A human-readable message describing the error.
35+
virtual const char *Message() = 0;
36+
37+
// System error code. If none is available it will return 0.
38+
virtual int ErrorCode() = 0;
39+
40+
// A general class the error falls into.
41+
virtual ErrorType Type() = 0;
42+
};
43+
44+
// The result of an IO operation.
45+
struct IOResult
46+
{
47+
// Set if there was an error.
48+
ke::Ref<IOError> Error;
49+
50+
// True if the connection was closed.
51+
bool Closed;
52+
53+
// Number of bytes that successfully completed.
54+
size_t Bytes;
55+
56+
IOResult() : Closed(false), Bytes(0)
57+
{}
58+
};
59+
60+
// A Transport is an abstraction around reading and writing (for example,
61+
// on POSIX systems, it is a file descriptor). Transports are always
62+
// asynchronous.
63+
class Transport : public ke::Refcounted<Transport>
64+
{
65+
public:
66+
virtual ~Transport()
67+
{}
68+
69+
// Attempts to read a number of bytes from the transport into the provided
70+
// |buffer|, up to |maxlength| bytes. If any bytes are read, the number
71+
// of bytes is returned and set in |result| accordingly.
72+
//
73+
// If the connection has been closed, |Closed| will be true in |result|.
74+
//
75+
// If an error occurs, |Error| will be set in |result|, and the result will
76+
// be -1.
77+
virtual ssize_t Read(IOResult *result, uint8_t *buffer, size_t maxlength) = 0;
78+
79+
// Attempts to write a number of bytes to the transport. If the transport
80+
// is connectionless (such as a datagram socket), all bytes are guaranteed
81+
// to be sent. Otherwise, only a partial number of bytes may be sent. The
82+
// number of bytes sent may be 0 without an error occurring.
83+
//
84+
// If an error occurs, |Error| will be set in |result|, and the result will
85+
// be -1.
86+
virtual ssize_t Write(IOResult *result, const uint8_t *buffer, size_t maxlength) = 0;
87+
88+
// Closes the transport, and frees any underlying operating system resources.
89+
// This does not free the C++ Transport object itself, which happens when
90+
// the object's reference count reaches 0.
91+
//
92+
// Close() is called automatically in the Transport's destructor.
93+
virtual void Close() = 0;
94+
};
95+
96+
// Used to receive notifications about status changes. All status notifications
97+
// are edge-triggered, meaning the status notification happens once, and it is
98+
// the user's responsibility to consume data.
99+
class StatusListener : public ke::Refcounted<StatusListener>
100+
{
101+
public:
102+
virtual ~StatusListener()
103+
{}
104+
105+
// Called when data is available for non-blocking reading.
106+
virtual void OnReadReady(ke::Ref<Transport> transport) = 0;
107+
108+
// Called when data is available for non-blocking sending.
109+
virtual void OnWriteReady(ke::Ref<Transport> transport) = 0;
110+
111+
// Called when the connection is closed.
112+
virtual void OnHangup(ke::Ref<Transport> transport) = 0;
113+
114+
// Called when an error state is received.
115+
virtual void OnError(ke::Ref<Transport> transport, ke::Ref<IOError> error) = 0;
116+
};
117+
118+
} // namespace amio
119+
120+
#endif // _include_amio_types_h_
121+

0 commit comments

Comments
 (0)