Updated SDL_net
This commit is contained in:
@@ -1,3 +1,29 @@
|
||||
1.2.8:
|
||||
Sam Lantinga - Sun Jan 15 01:39:35 EST 2012
|
||||
* Added the definition for INADDR_LOOPBACK
|
||||
Sam Lantinga - Thu Jan 05 22:57:56 2012 -0500
|
||||
* Added an Xcode project for iOS
|
||||
Sam Lantinga - Sat Dec 31 10:28:12 EST 2011
|
||||
* SDL_net is now under the zlib license
|
||||
Sam Lantinga - Sun Nov 20 01:29:33 EST 2011
|
||||
* Added SDLNet_UDP_SetPacketLoss() to simulate random packet loss
|
||||
Sam Lantinga - Fri Nov 04 04:52:12 2011 -0400
|
||||
* Added SDLNet_GetLocalAddresses() to query local interfaces
|
||||
Sam Lantinga - Fri Nov 4 04:05:03 EDT 2011
|
||||
* Removed obsolete OpenTransport code
|
||||
Sam Lantinga - Tue Mar 08 16:52:59 2011 -0800
|
||||
* Added Android.mk to build on the Android platform
|
||||
Sam Lantinga - Sun Feb 27 10:00:53 PST 2011
|
||||
* Fixed to compile cleanly with g++
|
||||
C.W. Betts - Thu Feb 17 12:52:47 PST 2011
|
||||
* Fixed the code to use socklen_t where appropriate
|
||||
Evan Nemerson - Thu Feb 17 12:47:13 PST 2011
|
||||
* Added pkg-config support
|
||||
esigra - Mon Feb 16 20:59:55 PST 2009
|
||||
* Fixed C++ compilation with -Wold-style-cast
|
||||
Matthew Mondor - Fri Jan 4 08:44:22 PST 2008
|
||||
* Enable multicast receiving on 224.0.0.1 on Windows (already worked on UNIX)
|
||||
|
||||
1.2.7:
|
||||
Joakim L. Gilje - Sat Jul 14 22:54:37 PDT 2007
|
||||
* Set server TCP sockets to blocking mode on Mac OS X, Solaris, etc.
|
||||
|
||||
@@ -1,458 +1,20 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ The latest version of this library is available from:
|
||||
http://www.libsdl.org/projects/SDL_net/
|
||||
|
||||
This is an example portable network library for use with SDL.
|
||||
It is available under the GNU Library General Public License.
|
||||
It is available under the zlib license, found in the file COPYING.
|
||||
The API can be found in the file SDL_net.h
|
||||
This library supports UNIX, Windows, MacOS Classic, MacOS X,
|
||||
BeOS and QNX.
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2004 Sam Lantinga
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id: SDLnet.c 2207 2006-04-20 16:48:25Z slouken $ */
|
||||
/* $Id$ */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_byteorder.h"
|
||||
#include "SDL_endian.h"
|
||||
|
||||
#include "SDLnetsys.h"
|
||||
#include "SDL_net.h"
|
||||
@@ -42,243 +41,24 @@ const SDL_version *SDLNet_Linked_Version(void)
|
||||
*/
|
||||
static int SDLNet_started = 0;
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
|
||||
#include <Events.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 stat;
|
||||
InetSvcRef dns;
|
||||
}DNSStatus, *DNSStatusRef;
|
||||
|
||||
enum
|
||||
{
|
||||
dnsNotReady = 0,
|
||||
dnsReady = 1,
|
||||
dnsResolved = 2,
|
||||
dnsError = 255
|
||||
};
|
||||
|
||||
//static InetSvcRef dns = 0;
|
||||
static DNSStatus dnsStatus;
|
||||
Uint32 OTlocalhost = 0;
|
||||
|
||||
/* We need a notifier for opening DNS.*/
|
||||
/* ( 010311 masahiro minami<elsur@aaa.letter.co.jp>) */
|
||||
static pascal void OpenDNSNotifier(
|
||||
void* context, OTEventCode code, OTResult result, void* cookie )
|
||||
{
|
||||
switch( code )
|
||||
{
|
||||
case T_OPENCOMPLETE:
|
||||
// DNS is ready now.
|
||||
if( result == kOTNoError )
|
||||
{
|
||||
dnsStatus.dns = (InetSvcRef)cookie;
|
||||
dnsStatus.stat = dnsReady;
|
||||
}
|
||||
else
|
||||
{
|
||||
SDLNet_SetError("T_DNRSTRINGTOADDRCOMPLETE event returned an error");
|
||||
dnsStatus.dns = NULL;
|
||||
dnsStatus.stat = dnsError;
|
||||
}
|
||||
break;
|
||||
case T_DNRSTRINGTOADDRCOMPLETE:
|
||||
// DNR resolved the name to address
|
||||
// WORK IN PROGRESS (TODO )
|
||||
dnsStatus.stat = dnsResolved;
|
||||
break;
|
||||
default:
|
||||
if( result != kOTNoError )
|
||||
dnsStatus.stat = dnsError;
|
||||
}
|
||||
// Is there anything else to be done here ???
|
||||
// ( 010311 masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
// (TODO)
|
||||
}
|
||||
|
||||
/* Local functions for initializing and cleaning up the DNS resolver */
|
||||
static int OpenDNS(void)
|
||||
{
|
||||
int retval;
|
||||
OSStatus status;
|
||||
|
||||
retval = 0;
|
||||
status = OTAsyncOpenInternetServices(
|
||||
kDefaultInternetServicesPath, 0, OpenDNSNotifier, NULL);
|
||||
if ( status == noErr ) {
|
||||
InetInterfaceInfo info;
|
||||
|
||||
dnsStatus.stat = dnsNotReady;
|
||||
|
||||
while( dnsStatus.stat != dnsError && dnsStatus.dns == NULL)
|
||||
{
|
||||
// what's to be done ? Yield ? WaitNextEvent ? or what ?
|
||||
// ( 010311 masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
//YieldToAnyThread();
|
||||
}
|
||||
/* Get the address of the local system -
|
||||
What should it be if ethernet is off?
|
||||
*/
|
||||
OTInetGetInterfaceInfo(&info, kDefaultInetInterface);
|
||||
OTlocalhost = info.fAddress;
|
||||
} else {
|
||||
SDLNet_SetError("Unable to open DNS handle");
|
||||
retval = status;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
}
|
||||
|
||||
static void CloseDNS(void)
|
||||
{
|
||||
if ( dnsStatus.dns ) {
|
||||
OTCloseProvider(dnsStatus.dns);
|
||||
dnsStatus.dns = 0;
|
||||
dnsStatus.stat = dnsNotReady;
|
||||
}
|
||||
|
||||
OTlocalhost = 0;
|
||||
}
|
||||
|
||||
/* Initialize/Cleanup the network API */
|
||||
int SDLNet_Init(void)
|
||||
{
|
||||
OSStatus status;
|
||||
int retval;
|
||||
|
||||
dnsStatus.stat = dnsNotReady;
|
||||
dnsStatus.dns = 0;
|
||||
|
||||
|
||||
retval = 0;
|
||||
if ( ! SDLNet_started ) {
|
||||
status = InitOpenTransport();
|
||||
if ( status == noErr ) {
|
||||
retval = OpenDNS();
|
||||
if ( retval < 0 ) {
|
||||
SDLNet_Quit();
|
||||
}
|
||||
} else {
|
||||
SDLNet_SetError("Unable to initialize Open Transport");
|
||||
retval = status;
|
||||
}
|
||||
}
|
||||
if ( retval == 0 ) {
|
||||
++SDLNet_started;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
void SDLNet_Quit(void)
|
||||
{
|
||||
if ( SDLNet_started == 0 ) {
|
||||
return;
|
||||
}
|
||||
if ( --SDLNet_started == 0 ) {
|
||||
CloseDNS();
|
||||
CloseOpenTransport();
|
||||
}
|
||||
}
|
||||
|
||||
/* Resolve a host name and port to an IP address in network form */
|
||||
int SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
/* Perform the actual host resolution */
|
||||
if ( host == NULL ) {
|
||||
address->host = INADDR_ANY;
|
||||
} else {
|
||||
/* int a[4];
|
||||
|
||||
address->host = INADDR_NONE;
|
||||
|
||||
if ( sscanf(host, "%d.%d.%d.%d", a, a+1, a+2, a+3) == 4 ) {
|
||||
if ( !(a[0] & 0xFFFFFF00) && !(a[1] & 0xFFFFFF00) &&
|
||||
!(a[2] & 0xFFFFFF00) && !(a[3] & 0xFFFFFF00) ) {
|
||||
address->host = ((a[0] << 24) |
|
||||
(a[1] << 16) |
|
||||
(a[2] << 8) | a[3]);
|
||||
if ( address->host == 0x7F000001 ) {
|
||||
address->host = OTlocalhost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( address->host == INADDR_NONE ) {*/
|
||||
InetHostInfo hinfo;
|
||||
|
||||
/* Check for special case - localhost */
|
||||
if ( strcmp(host, "localhost") == 0 )
|
||||
return(SDLNet_ResolveHost(address, "127.0.0.1", port));
|
||||
|
||||
/* Have OpenTransport resolve the hostname for us */
|
||||
retval = OTInetStringToAddress(dnsStatus.dns, (char *)host, &hinfo);
|
||||
if (retval == noErr) {
|
||||
while( dnsStatus.stat != dnsResolved )
|
||||
{WaitNextEvent(everyEvent, 0, 1, NULL );}
|
||||
address->host = hinfo.addrs[0];
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
address->port = SDL_SwapBE16(port);
|
||||
|
||||
/* Return the status */
|
||||
return(retval);
|
||||
}
|
||||
|
||||
/* Resolve an ip address to a host name in canonical form.
|
||||
If the ip couldn't be resolved, this function returns NULL,
|
||||
otherwise a pointer to a static buffer containing the hostname
|
||||
is returned. Note that this function is not thread-safe.
|
||||
*/
|
||||
/* MacOS implementation by Roy Wood
|
||||
*/
|
||||
const char *SDLNet_ResolveIP(IPaddress *ip)
|
||||
{
|
||||
if (ip != nil)
|
||||
{
|
||||
InetHost theIP;
|
||||
static InetDomainName theInetDomainName;
|
||||
OSStatus theOSStatus;
|
||||
|
||||
|
||||
/* Default result will be null string */
|
||||
|
||||
theInetDomainName[0] = '\0';
|
||||
|
||||
|
||||
/* Do a reverse DNS lookup */
|
||||
|
||||
theIP = ip->host;
|
||||
|
||||
theOSStatus = OTInetAddressToName(dnsStatus.dns,theIP,theInetDomainName);
|
||||
|
||||
/* If successful, return the result */
|
||||
|
||||
if (theOSStatus == kOTNoError)
|
||||
{
|
||||
while( dnsStatus.stat != dnsResolved )
|
||||
{ /*should we yield or what ? */ }
|
||||
return(theInetDomainName);
|
||||
}
|
||||
}
|
||||
|
||||
SDLNet_SetError("Can't perform reverse DNS lookup");
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#else /* !MACOS_OPENTRANSPORT */
|
||||
|
||||
#ifndef __USE_W32_SOCKETS
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifndef __USE_W32_SOCKETS
|
||||
|
||||
int SDLNet_GetLastError(void)
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
void SDLNet_SetLastError(int err)
|
||||
{
|
||||
errno = err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Initialize/Cleanup the network API */
|
||||
int SDLNet_Init(void)
|
||||
{
|
||||
@@ -314,7 +94,9 @@ void SDLNet_Quit(void)
|
||||
/* Clean up windows networking */
|
||||
if ( WSACleanup() == SOCKET_ERROR ) {
|
||||
if ( WSAGetLastError() == WSAEINPROGRESS ) {
|
||||
#ifndef _WIN32_WCE
|
||||
WSACancelBlockingCall();
|
||||
#endif
|
||||
WSACleanup();
|
||||
}
|
||||
}
|
||||
@@ -365,18 +147,94 @@ int SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)
|
||||
* Main Programmer of Arianne RPG.
|
||||
* http://come.to/arianne_rpg
|
||||
*/
|
||||
const char *SDLNet_ResolveIP(IPaddress *ip)
|
||||
const char *SDLNet_ResolveIP(const IPaddress *ip)
|
||||
{
|
||||
struct hostent *hp;
|
||||
struct in_addr in;
|
||||
|
||||
hp = gethostbyaddr((char *)&ip->host, 4, AF_INET);
|
||||
hp = gethostbyaddr((const char *)&ip->host, sizeof(ip->host), AF_INET);
|
||||
if ( hp != NULL ) {
|
||||
return hp->h_name;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
in.s_addr = ip->host;
|
||||
return inet_ntoa(in);
|
||||
}
|
||||
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
int SDLNet_GetLocalAddresses(IPaddress *addresses, int maxcount)
|
||||
{
|
||||
int count = 0;
|
||||
#ifdef SIOCGIFCONF
|
||||
/* Defined on Mac OS X */
|
||||
#ifndef _SIZEOF_ADDR_IFREQ
|
||||
#define _SIZEOF_ADDR_IFREQ sizeof
|
||||
#endif
|
||||
SOCKET sock;
|
||||
struct ifconf conf;
|
||||
char data[4096];
|
||||
struct ifreq *ifr;
|
||||
struct sockaddr_in *sock_addr;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
conf.ifc_len = sizeof(data);
|
||||
conf.ifc_buf = (caddr_t) data;
|
||||
if ( ioctl(sock, SIOCGIFCONF, &conf) < 0 ) {
|
||||
closesocket(sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ifr = (struct ifreq*)data;
|
||||
while ((char*)ifr < data+conf.ifc_len) {
|
||||
if (ifr->ifr_addr.sa_family == AF_INET) {
|
||||
if (count < maxcount) {
|
||||
sock_addr = (struct sockaddr_in*)&ifr->ifr_addr;
|
||||
addresses[count].host = sock_addr->sin_addr.s_addr;
|
||||
addresses[count].port = sock_addr->sin_port;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
ifr = (struct ifreq*)((char*)ifr + _SIZEOF_ADDR_IFREQ(*ifr));
|
||||
}
|
||||
closesocket(sock);
|
||||
#elif defined(__WIN32__)
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pAdapter;
|
||||
PIP_ADDR_STRING pAddress;
|
||||
DWORD dwRetVal = 0;
|
||||
ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
|
||||
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *) SDL_malloc(sizeof (IP_ADAPTER_INFO));
|
||||
if (pAdapterInfo == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == ERROR_BUFFER_OVERFLOW) {
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *) SDL_realloc(pAdapterInfo, ulOutBufLen);
|
||||
if (pAdapterInfo == NULL) {
|
||||
return 0;
|
||||
}
|
||||
dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
|
||||
}
|
||||
|
||||
if (dwRetVal == NO_ERROR) {
|
||||
for (pAdapter = pAdapterInfo; pAdapter; pAdapter = pAdapter->Next) {
|
||||
for (pAddress = &pAdapterInfo->IpAddressList; pAddress; pAddress = pAddress->Next) {
|
||||
if (count < maxcount) {
|
||||
addresses[count].host = inet_addr(pAddress->IpAddress.String);
|
||||
addresses[count].port = 0;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_free(pAdapterInfo);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
#if !SDL_DATA_ALIGNED /* function versions for binary compatibility */
|
||||
|
||||
@@ -409,22 +267,3 @@ Uint32 SDLNet_Read32(void *areap)
|
||||
}
|
||||
|
||||
#endif /* !SDL_DATA_ALIGNED */
|
||||
|
||||
|
||||
#ifdef USE_GUSI_SOCKETS
|
||||
|
||||
/* Configure Socket Factories */
|
||||
|
||||
void GUSISetupFactories()
|
||||
{
|
||||
GUSIwithInetSockets();
|
||||
}
|
||||
|
||||
/* Configure File Devices */
|
||||
|
||||
void GUSISetupDevices()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* USE_GUSI_SOCKETS */
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2004 Sam Lantinga
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id: SDLnetTCP.c 3280 2007-07-15 05:55:42Z slouken $ */
|
||||
/* $Id$ */
|
||||
|
||||
#include "SDLnetsys.h"
|
||||
#include "SDL_net.h"
|
||||
@@ -31,657 +30,6 @@
|
||||
we'll just have two completely different sections here.
|
||||
*/
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
|
||||
#include <Events.h>
|
||||
#include <Threads.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTptInternet.h>
|
||||
#include <OTDebug.h>
|
||||
|
||||
struct _TCPsocket {
|
||||
int ready;
|
||||
SOCKET channel;
|
||||
|
||||
// These are taken from GUSI interface.
|
||||
// I'm not sure if it's really necessary here yet
|
||||
// ( masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
// ( 01/02/19 )
|
||||
OTEventCode curEvent;
|
||||
OTEventCode newEvent;
|
||||
OTEventCode event;
|
||||
OTEventCode curCompletion;
|
||||
OTEventCode newCompletion;
|
||||
OTEventCode completion;
|
||||
OSStatus error;
|
||||
TEndpointInfo info;
|
||||
Boolean readShutdown;
|
||||
Boolean writeShutdown;
|
||||
Boolean connected;
|
||||
OTConfigurationRef config; // Master configuration. you can clone this.
|
||||
TCPsocket nextListener;
|
||||
// ( end of new members --- masahiro minami<elsur@aaa.letter.co.jp>
|
||||
|
||||
IPaddress remoteAddress;
|
||||
IPaddress localAddress;
|
||||
int sflag;
|
||||
|
||||
// Maybe we don't need this---- it's from original SDL_net
|
||||
// (masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
// ( 01/02/20 )
|
||||
int rcvdPassConn;
|
||||
};
|
||||
|
||||
// To be used in WaitNextEvent() here and there....
|
||||
// (010311 masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
EventRecord macEvent;
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
/* for Carbon */
|
||||
OTNotifyUPP notifier;
|
||||
#endif
|
||||
|
||||
/* Input: ep - endpointref on which to negotiate the option
|
||||
enableReuseIPMode - desired option setting - true/false
|
||||
Return: kOTNoError indicates that the option was successfully negotiated
|
||||
OSStatus is an error if < 0, otherwise, the status field is
|
||||
returned and is > 0.
|
||||
|
||||
IMPORTANT NOTE: The endpoint is assumed to be in synchronous more, otherwise
|
||||
this code will not function as desired
|
||||
*/
|
||||
|
||||
/*
|
||||
NOTE: As this version is written async way, we don't use this function...
|
||||
(010526) masahiro minami<elsur@aaa.letter.co.jp>
|
||||
*/
|
||||
/*
|
||||
OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode)
|
||||
|
||||
{
|
||||
UInt8 buf[kOTFourByteOptionSize]; // define buffer for fourByte Option size
|
||||
TOption* opt; // option ptr to make items easier to access
|
||||
TOptMgmt req;
|
||||
TOptMgmt ret;
|
||||
OSStatus err;
|
||||
|
||||
if (!OTIsSynchronous(ep))
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
opt = (TOption*)buf; // set option ptr to buffer
|
||||
req.opt.buf = buf;
|
||||
req.opt.len = sizeof(buf);
|
||||
req.flags = T_NEGOTIATE; // negotiate for option
|
||||
|
||||
ret.opt.buf = buf;
|
||||
ret.opt.maxlen = kOTFourByteOptionSize;
|
||||
|
||||
opt->level = INET_IP; // dealing with an IP Level function
|
||||
opt->name = IP_REUSEADDR;
|
||||
opt->len = kOTFourByteOptionSize;
|
||||
opt->status = 0;
|
||||
*(UInt32*)opt->value = enableReuseIPMode; // set the desired option level, true or false
|
||||
|
||||
err = OTOptionManagement(ep, &req, &ret);
|
||||
|
||||
// if no error then return the option status value
|
||||
if (err == kOTNoError)
|
||||
{
|
||||
if (opt->status != T_SUCCESS)
|
||||
err = opt->status;
|
||||
else
|
||||
err = kOTNoError;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
*/
|
||||
|
||||
/* A helper function for Mac OpenTransport support*/
|
||||
// This function is a complete copy from GUSI
|
||||
// ( masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
// ( 01/02/19 )
|
||||
static __inline__ Uint32 CompleteMask(OTEventCode code)
|
||||
{
|
||||
return 1 << (code & 0x1F);
|
||||
}
|
||||
|
||||
/* Notifier for async OT calls */
|
||||
static pascal void AsyncTCPNotifier( TCPsocket sock, OTEventCode code,
|
||||
OTResult result, void* cookie )
|
||||
{
|
||||
|
||||
#ifdef DEBUG_NET
|
||||
printf("AsyncTCPNotifier got an event : 0x%8.8x\n", code );
|
||||
#endif
|
||||
|
||||
switch( code & 0x7f000000L)
|
||||
{
|
||||
case 0:
|
||||
sock->newEvent |= code;
|
||||
result = 0;
|
||||
break;
|
||||
case kCOMPLETEEVENT:
|
||||
if(!(code & 0x00FFFFE0 ))
|
||||
sock->newCompletion |= CompleteMask( code );
|
||||
if( code == T_OPENCOMPLETE )
|
||||
sock->channel = (SOCKET)(cookie);
|
||||
break;
|
||||
default:
|
||||
if( code != kOTProviderWillClose )
|
||||
result = 0;
|
||||
}
|
||||
// Do we need these ???? TODO
|
||||
// sock->SetAsyncMacError( result );
|
||||
// sock->Wakeup();
|
||||
}
|
||||
|
||||
/* Retrieve OT event */
|
||||
// This function is taken from GUSI interface.
|
||||
// ( 01/02/19 masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
static void AsyncTCPPopEvent( TCPsocket sock )
|
||||
{
|
||||
// Make sure OT calls are not interrupted
|
||||
// Not sure if we really need this.
|
||||
OTEnterNotifier( sock->channel );
|
||||
|
||||
sock->event |= (sock->curEvent = sock->newEvent );
|
||||
sock->completion |= ( sock->curCompletion = sock->newCompletion );
|
||||
sock->newEvent = sock->newCompletion = 0;
|
||||
|
||||
OTLeaveNotifier( sock->channel );
|
||||
|
||||
if( sock->curEvent & T_UDERR)
|
||||
{
|
||||
// We just clear the error.
|
||||
// Should we feed this back to users ?
|
||||
// (TODO )
|
||||
OTRcvUDErr( sock->channel, NULL );
|
||||
|
||||
#ifdef DEBUG_NET
|
||||
printf("AsyncTCPPopEvent T_UDERR recognized");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Remote is disconnecting...
|
||||
if( sock->curEvent & ( T_DISCONNECT | T_ORDREL ))
|
||||
{
|
||||
sock->readShutdown = true;
|
||||
}
|
||||
|
||||
if( sock->curEvent &T_CONNECT )
|
||||
{
|
||||
// Ignore the info of remote (second parameter).
|
||||
// Shoule we care ?
|
||||
// (TODO)
|
||||
OTRcvConnect( sock->channel, NULL );
|
||||
sock->connected = 1;
|
||||
}
|
||||
|
||||
if( sock->curEvent & T_ORDREL )
|
||||
{
|
||||
OTRcvOrderlyDisconnect( sock->channel );
|
||||
}
|
||||
|
||||
if( sock->curEvent & T_DISCONNECT )
|
||||
{
|
||||
OTRcvDisconnect( sock->channel, NULL );
|
||||
}
|
||||
|
||||
// Do we need to ?
|
||||
// (masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
//YieldToAnyThread();
|
||||
}
|
||||
|
||||
/* Create a new TCPsocket */
|
||||
// Because TCPsocket structure gets bigger and bigger,
|
||||
// I think we'd better have a constructor function and delete function.
|
||||
// ( 01/02/25 masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
static TCPsocket AsyncTCPNewSocket()
|
||||
{
|
||||
TCPsocket sock;
|
||||
|
||||
sock = (TCPsocket)malloc(sizeof(*sock));
|
||||
if ( sock == NULL ) {
|
||||
SDLNet_SetError("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->newEvent = 0;
|
||||
sock->event = 0;
|
||||
sock->curEvent = 0;
|
||||
sock->newCompletion = 0;
|
||||
sock->completion = 0;
|
||||
sock->curCompletion = 0;
|
||||
//sock->info = NULL;
|
||||
sock->readShutdown = sock->writeShutdown = sock->connected = false;
|
||||
sock->error = 0;
|
||||
sock->config = NULL;
|
||||
sock->nextListener = NULL;
|
||||
sock->sflag = 0;
|
||||
return sock;
|
||||
}
|
||||
|
||||
// hmmm.... do we need this ???
|
||||
// ( 01/02/25 masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
static void AsycnTCPDeleteSocket( TCPsocket sock )
|
||||
{
|
||||
SDLNet_TCP_Close( sock );
|
||||
}
|
||||
/* Open a TCP network socket
|
||||
If 'remote' is NULL, this creates a local server socket on the given port,
|
||||
otherwise a TCP connection to the remote host and port is attempted.
|
||||
The newly created socket is returned, or NULL if there was an error.
|
||||
|
||||
( re-written by masahiro minami<elsur@aaa.letter.co.jp>
|
||||
Now endpoint is created in Async mode.
|
||||
01/02/20 )
|
||||
*/
|
||||
TCPsocket SDLNet_TCP_Open(IPaddress *ip)
|
||||
{
|
||||
EndpointRef dummy = NULL;
|
||||
|
||||
TCPsocket sock = AsyncTCPNewSocket();
|
||||
if( ! sock)
|
||||
return NULL;
|
||||
|
||||
// Determin whether bind locally, or connect to remote
|
||||
if ( (ip->host != INADDR_NONE) && (ip->host != INADDR_ANY) )
|
||||
{
|
||||
// ######## Connect to remote
|
||||
OTResult stat;
|
||||
InetAddress inAddr;
|
||||
TBind bindReq;
|
||||
|
||||
// Open endpoint
|
||||
sock->error = OTAsyncOpenEndpoint(
|
||||
OTCreateConfiguration(kTCPName), NULL, &(sock->info),
|
||||
(OTNotifyProcPtr)(AsyncTCPNotifier),
|
||||
sock );
|
||||
|
||||
AsyncTCPPopEvent( sock );
|
||||
while( !sock->error && !( sock->completion & CompleteMask(T_OPENCOMPLETE)))
|
||||
{
|
||||
//SetThreadState( kCurrentThreadID, kReadyThreadState, kNoThreadID );
|
||||
//YieldToAnyThread();
|
||||
//WaitNextEvent(everyEvent, &macEvent, 1, NULL);
|
||||
AsyncTCPPopEvent( sock );
|
||||
}
|
||||
|
||||
if( !sock->channel )
|
||||
{
|
||||
SDLNet_SetError("OTAsyncOpenEndpoint failed --- client socket could not be opened");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
// Set blocking mode
|
||||
// I'm not sure if this is a good solution....
|
||||
// Check out Apple's sample code, OT Virtual Server
|
||||
// ( 010314 masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
|
||||
sock->error = OTSetBlocking( sock->channel );
|
||||
if( sock->error != kOTNoError )
|
||||
{
|
||||
SDLNet_SetError("OTSetBlocking() returned an error");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
// Bind the socket
|
||||
OTInitInetAddress(&inAddr, 0, 0 );
|
||||
bindReq.addr.len = sizeof( InetAddress );
|
||||
bindReq.addr.buf = (unsigned char*)&inAddr;
|
||||
bindReq.qlen = 0;
|
||||
|
||||
sock->error = OTBind( sock->channel, &bindReq, NULL );
|
||||
AsyncTCPPopEvent(sock);
|
||||
while( !sock->error && !( sock->completion & CompleteMask(T_BINDCOMPLETE)))
|
||||
{
|
||||
//YieldToAnyThread();
|
||||
//WaitNextEvent(everyEvent, &macEvent, 1, NULL);
|
||||
AsyncTCPPopEvent(sock);
|
||||
}
|
||||
|
||||
|
||||
switch( stat = OTGetEndpointState( sock->channel ))
|
||||
{
|
||||
InetAddress inAddr;
|
||||
TCall sndCall;
|
||||
OTResult res;
|
||||
|
||||
case T_OUTCON:
|
||||
SDLNet_SetError("SDLNet_Open() failed -- T_OUTCON");
|
||||
goto error_return;
|
||||
break;
|
||||
case T_IDLE:
|
||||
sock->readShutdown = false;
|
||||
sock->writeShutdown = false;
|
||||
sock->event &=~T_CONNECT;
|
||||
|
||||
OTMemzero(&sndCall, sizeof(TCall));
|
||||
OTInitInetAddress(&inAddr, ip->port, ip->host );
|
||||
sndCall.addr.len = sizeof(InetAddress);
|
||||
sndCall.addr.buf = (unsigned char*)&inAddr;
|
||||
sock->connected = 0;
|
||||
res = OTConnect( sock->channel, &sndCall, NULL );
|
||||
AsyncTCPPopEvent(sock);
|
||||
while( sock->error == kOTNoDataErr || !sock->connected )
|
||||
AsyncTCPPopEvent(sock);
|
||||
break;
|
||||
default:
|
||||
// What's to be done ? (TODO)
|
||||
SDLNet_SetError("SDLNet_TCP_Open() failed -- EndpointState not good");
|
||||
goto error_return;
|
||||
|
||||
}
|
||||
if( !(sock->event & (T_CONNECT|T_DISCONNECT)))
|
||||
goto error_return;
|
||||
|
||||
AsyncTCPPopEvent( sock );
|
||||
while( !(sock->event & (T_CONNECT|T_DISCONNECT)))
|
||||
{
|
||||
AsyncTCPPopEvent( sock );
|
||||
}
|
||||
// OTConnect successfull
|
||||
if( sock->event & T_CONNECT)
|
||||
{
|
||||
sock->remoteAddress.host = inAddr.fHost;
|
||||
sock->remoteAddress.port = inAddr.fPort;
|
||||
sock->sflag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// OTConnect failed
|
||||
sock->event &= ~T_DISCONNECT;
|
||||
goto error_return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ######## Bind locally
|
||||
TBind bindReq;
|
||||
InetAddress inAddr;
|
||||
|
||||
// First, get InetInterfaceInfo.
|
||||
// I don't search for all of them.
|
||||
// Does that matter ?
|
||||
|
||||
sock->error = OTAsyncOpenEndpoint(
|
||||
OTCreateConfiguration("tilisten, tcp"), NULL, &(sock->info),
|
||||
(OTNotifyProcPtr)(AsyncTCPNotifier),
|
||||
sock);
|
||||
AsyncTCPPopEvent( sock );
|
||||
while( !sock->error && !( sock->completion & CompleteMask( T_OPENCOMPLETE)))
|
||||
{
|
||||
AsyncTCPPopEvent( sock );
|
||||
}
|
||||
|
||||
if( ! sock->channel )
|
||||
{
|
||||
SDLNet_SetError("OTAsyncOpenEndpoint failed --- server socket could not be opened");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
// Create a master OTConfiguration
|
||||
sock->config = OTCreateConfiguration(kTCPName);
|
||||
if( ! sock->config )
|
||||
{
|
||||
SDLNet_SetError("Could not create master OTConfiguration");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
// Bind the socket
|
||||
OTInitInetAddress(&inAddr, ip->port, 0 );
|
||||
inAddr.fAddressType = AF_INET;
|
||||
bindReq.addr.len = sizeof( InetAddress );
|
||||
bindReq.addr.buf = (unsigned char*)&inAddr;
|
||||
bindReq.qlen = 35; // This number is NOT well considered. (TODO)
|
||||
sock->localAddress.host = inAddr.fHost;
|
||||
sock->localAddress.port = inAddr.fPort;
|
||||
sock->sflag = true;
|
||||
|
||||
sock->error = OTBind( sock->channel, &bindReq, NULL );
|
||||
AsyncTCPPopEvent(sock);
|
||||
while( !sock->error && !( sock->completion & CompleteMask(T_BINDCOMPLETE)))
|
||||
{
|
||||
AsyncTCPPopEvent(sock);
|
||||
}
|
||||
if( sock->error != kOTNoError )
|
||||
{
|
||||
SDLNet_SetError("Could not bind server socket");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
if( dummy )
|
||||
OTCloseProvider( dummy );
|
||||
|
||||
}
|
||||
|
||||
sock->ready = 0;
|
||||
return sock;
|
||||
|
||||
error_return:
|
||||
if( dummy )
|
||||
OTCloseProvider( dummy );
|
||||
SDLNet_TCP_Close( sock );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Accept an incoming connection on the given server socket.
|
||||
The newly created socket is returned, or NULL if there was an error.
|
||||
*/
|
||||
TCPsocket SDLNet_TCP_Accept(TCPsocket server)
|
||||
{
|
||||
|
||||
/* Only server sockets can accept */
|
||||
if ( ! server->sflag ) {
|
||||
SDLNet_SetError("Only server sockets can accept()");
|
||||
return(NULL);
|
||||
}
|
||||
server->ready = 0;
|
||||
|
||||
/* Accept a new TCP connection on a server socket */
|
||||
{
|
||||
InetAddress peer;
|
||||
TCall peerinfo;
|
||||
TCPsocket sock = NULL;
|
||||
Boolean mustListen = false;
|
||||
OTResult err;
|
||||
|
||||
memset(&peerinfo, 0, (sizeof peerinfo ));
|
||||
peerinfo.addr.buf = (Uint8 *) &peer;
|
||||
peerinfo.addr.maxlen = sizeof(peer);
|
||||
|
||||
while( mustListen || !sock )
|
||||
{
|
||||
// OTListen
|
||||
// We do NOT block ---- right thing ? (TODO)
|
||||
err = OTListen( server->channel, &peerinfo );
|
||||
|
||||
if( err )
|
||||
goto error_return;
|
||||
else
|
||||
{
|
||||
mustListen = false;
|
||||
sock = AsyncTCPNewSocket();
|
||||
if( ! sock )
|
||||
goto error_return;
|
||||
}
|
||||
}
|
||||
if( sock )
|
||||
{
|
||||
// OTAsyncOpenEndpoint
|
||||
server->error = OTAsyncOpenEndpoint( OTCloneConfiguration( server->config ),
|
||||
NULL, &(sock->info), (OTNotifyProcPtr)AsyncTCPNotifier, sock );
|
||||
AsyncTCPPopEvent( sock );
|
||||
while( !sock->error && !( sock->completion & CompleteMask( T_OPENCOMPLETE)))
|
||||
{
|
||||
AsyncTCPPopEvent( sock );
|
||||
}
|
||||
if( ! sock->channel )
|
||||
{
|
||||
mustListen = false;
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
// OTAccept
|
||||
server->completion &= ~(CompleteMask(T_ACCEPTCOMPLETE));
|
||||
server->error = OTAccept( server->channel, sock->channel, &peerinfo );
|
||||
AsyncTCPPopEvent( server );
|
||||
while( !(server->completion & CompleteMask(T_ACCEPTCOMPLETE)))
|
||||
{
|
||||
AsyncTCPPopEvent( server );
|
||||
}
|
||||
|
||||
switch( server->error )
|
||||
{
|
||||
case kOTLookErr:
|
||||
switch( OTLook(server->channel ))
|
||||
{
|
||||
case T_LISTEN:
|
||||
mustListen = true;
|
||||
break;
|
||||
case T_DISCONNECT:
|
||||
goto error_return;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
sock->nextListener = server->nextListener;
|
||||
server->nextListener = sock;
|
||||
sock->remoteAddress.host = peer.fHost;
|
||||
sock->remoteAddress.port = peer.fPort;
|
||||
return sock;
|
||||
// accept successful
|
||||
break;
|
||||
default:
|
||||
free( sock );
|
||||
}
|
||||
}
|
||||
sock->remoteAddress.host = peer.fHost;
|
||||
sock->remoteAddress.port = peer.fPort;
|
||||
sock->sflag = 0;
|
||||
sock->ready = 0;
|
||||
|
||||
/* The socket is ready */
|
||||
return(sock);
|
||||
|
||||
// Error; close the socket and return
|
||||
error_return:
|
||||
SDLNet_TCP_Close(sock);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the IP address of the remote system associated with the socket.
|
||||
If the socket is a server socket, this function returns NULL.
|
||||
*/
|
||||
IPaddress *SDLNet_TCP_GetPeerAddress(TCPsocket sock)
|
||||
{
|
||||
if ( sock->sflag ) {
|
||||
return(NULL);
|
||||
}
|
||||
return(&sock->remoteAddress);
|
||||
}
|
||||
|
||||
/* Send 'len' bytes of 'data' over the non-server socket 'sock'
|
||||
This function returns the actual amount of data sent. If the return value
|
||||
is less than the amount of data sent, then either the remote connection was
|
||||
closed, or an unknown socket error occurred.
|
||||
*/
|
||||
int SDLNet_TCP_Send(TCPsocket sock, const void *datap, int len)
|
||||
{
|
||||
const Uint8 *data = (const Uint8 *)datap; /* For pointer arithmetic */
|
||||
int sent, left;
|
||||
|
||||
/* Server sockets are for accepting connections only */
|
||||
if ( sock->sflag ) {
|
||||
SDLNet_SetError("Server sockets cannot send");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Keep sending data until it's sent or an error occurs */
|
||||
left = len;
|
||||
sent = 0;
|
||||
errno = 0;
|
||||
do {
|
||||
len = OTSnd(sock->channel, (void *)data, left, 0);
|
||||
if (len == kOTFlowErr)
|
||||
len = 0;
|
||||
if ( len > 0 ) {
|
||||
sent += len;
|
||||
left -= len;
|
||||
data += len;
|
||||
}
|
||||
// Do we need to ?
|
||||
// ( masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
// (TODO)
|
||||
//WaitNextEvent(everyEvent, &macEvent, 1, NULL);
|
||||
//AsyncTCPPopEvent(sock);
|
||||
} while ( (left > 0) && (len > 0) );
|
||||
|
||||
return(sent);
|
||||
}
|
||||
|
||||
/* Receive up to 'maxlen' bytes of data over the non-server socket 'sock',
|
||||
and store them in the buffer pointed to by 'data'.
|
||||
This function returns the actual amount of data received. If the return
|
||||
value is less than or equal to zero, then either the remote connection was
|
||||
closed, or an unknown socket error occurred.
|
||||
*/
|
||||
int SDLNet_TCP_Recv(TCPsocket sock, void *data, int maxlen)
|
||||
{
|
||||
int len = 0;
|
||||
OSStatus res;
|
||||
/* Server sockets are for accepting connections only */
|
||||
if ( sock->sflag ) {
|
||||
SDLNet_SetError("Server sockets cannot receive");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
res = OTRcv(sock->channel, data, maxlen-len, 0);
|
||||
if (res > 0) {
|
||||
len = res;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_NET
|
||||
if ( res != kOTNoDataErr )
|
||||
printf("SDLNet_TCP_Recv received ; %d\n", res );
|
||||
#endif
|
||||
|
||||
AsyncTCPPopEvent(sock);
|
||||
if( res == kOTLookErr )
|
||||
{
|
||||
res = OTLook(sock->channel );
|
||||
continue;
|
||||
}
|
||||
} while ( (len == 0) && (res == kOTNoDataErr) );
|
||||
|
||||
sock->ready = 0;
|
||||
if ( len == 0 ) { /* Open Transport error */
|
||||
#ifdef DEBUG_NET
|
||||
printf("Open Transport error: %d\n", res);
|
||||
#endif
|
||||
return(-1);
|
||||
}
|
||||
return(len);
|
||||
}
|
||||
|
||||
/* Close a TCP network socket */
|
||||
void SDLNet_TCP_Close(TCPsocket sock)
|
||||
{
|
||||
if ( sock != NULL ) {
|
||||
if ( sock->channel != INVALID_SOCKET ) {
|
||||
//closesocket(sock->channel);
|
||||
OTSndOrderlyDisconnect( sock->channel );
|
||||
}
|
||||
free(sock);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* !MACOS_OPENTRANSPORT */
|
||||
|
||||
struct _TCPsocket {
|
||||
int ready;
|
||||
SOCKET channel;
|
||||
@@ -817,7 +165,7 @@ TCPsocket SDLNet_TCP_Accept(TCPsocket server)
|
||||
{
|
||||
TCPsocket sock;
|
||||
struct sockaddr_in sock_addr;
|
||||
int sock_alen;
|
||||
socklen_t sock_alen;
|
||||
|
||||
/* Only server sockets can accept */
|
||||
if ( ! server->sflag ) {
|
||||
@@ -836,12 +184,8 @@ TCPsocket SDLNet_TCP_Accept(TCPsocket server)
|
||||
/* Accept a new TCP connection on a server socket */
|
||||
sock_alen = sizeof(sock_addr);
|
||||
sock->channel = accept(server->channel, (struct sockaddr *)&sock_addr,
|
||||
#ifdef USE_GUSI_SOCKETS
|
||||
(unsigned int *)&sock_alen);
|
||||
#else
|
||||
&sock_alen);
|
||||
#endif
|
||||
if ( sock->channel == SOCKET_ERROR ) {
|
||||
if ( sock->channel == INVALID_SOCKET ) {
|
||||
SDLNet_SetError("accept() failed");
|
||||
goto error_return;
|
||||
}
|
||||
@@ -901,7 +245,7 @@ int SDLNet_TCP_Send(TCPsocket sock, const void *datap, int len)
|
||||
/* Keep sending data until it's sent or an error occurs */
|
||||
left = len;
|
||||
sent = 0;
|
||||
errno = 0;
|
||||
SDLNet_SetLastError(0);
|
||||
do {
|
||||
len = send(sock->channel, (const char *) data, left, 0);
|
||||
if ( len > 0 ) {
|
||||
@@ -909,7 +253,7 @@ int SDLNet_TCP_Send(TCPsocket sock, const void *datap, int len)
|
||||
left -= len;
|
||||
data += len;
|
||||
}
|
||||
} while ( (left > 0) && ((len > 0) || (errno == EINTR)) );
|
||||
} while ( (left > 0) && ((len > 0) || (SDLNet_GetLastError() == EINTR)) );
|
||||
|
||||
return(sent);
|
||||
}
|
||||
@@ -930,10 +274,10 @@ int SDLNet_TCP_Recv(TCPsocket sock, void *data, int maxlen)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
SDLNet_SetLastError(0);
|
||||
do {
|
||||
len = recv(sock->channel, (char *) data, maxlen, 0);
|
||||
} while ( errno == EINTR );
|
||||
} while ( SDLNet_GetLastError() == EINTR );
|
||||
|
||||
sock->ready = 0;
|
||||
return(len);
|
||||
@@ -949,5 +293,3 @@ void SDLNet_TCP_Close(TCPsocket sock)
|
||||
free(sock);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
|
||||
@@ -1,187 +1,50 @@
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2004 Sam Lantinga
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id: SDLnetUDP.c 1192 2004-01-04 17:41:55Z slouken $ */
|
||||
/* $Id$ */
|
||||
|
||||
#include "SDLnetsys.h"
|
||||
#include "SDL_net.h"
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
#include <Events.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define srandom srand
|
||||
#define random rand
|
||||
#endif
|
||||
|
||||
struct UDP_channel {
|
||||
int numbound;
|
||||
IPaddress address[SDLNET_MAX_UDPADDRESSES];
|
||||
};
|
||||
|
||||
struct _UDPsocket {
|
||||
int ready;
|
||||
SOCKET channel;
|
||||
IPaddress address;
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
OTEventCode newEvent;
|
||||
OTEventCode event;
|
||||
OTEventCode curEvent;
|
||||
OTEventCode newCompletion;
|
||||
OTEventCode completion;
|
||||
OTEventCode curCompletion;
|
||||
TEndpointInfo info;
|
||||
Boolean readShutdown;
|
||||
Boolean writeShutdown;
|
||||
OSStatus error;
|
||||
OTConfigurationRef config; // Master configuration. you can clone this.
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
struct UDP_channel binding[SDLNET_MAX_UDPCHANNELS];
|
||||
|
||||
struct UDP_channel {
|
||||
int numbound;
|
||||
IPaddress address[SDLNET_MAX_UDPADDRESSES];
|
||||
} binding[SDLNET_MAX_UDPCHANNELS];
|
||||
/* For debugging purposes */
|
||||
int packetloss;
|
||||
};
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
|
||||
/* A helper function for Mac OpenTransport support*/
|
||||
// This function is a complete copy from GUSI
|
||||
// ( masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
// ( 01/02/19 )
|
||||
//
|
||||
// I guess this function should be put in SDLnet.c
|
||||
// ( 010315 masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
// (TODO)
|
||||
static __inline__ Uint32 CompleteMask(OTEventCode code)
|
||||
{
|
||||
return 1 << (code & 0x1F);
|
||||
}
|
||||
|
||||
/* Notifier for async OT calls */
|
||||
// This function is completely same as AsyncTCPNotifier,
|
||||
// except for the argument, UDPsocket / TCPsocket
|
||||
// ( 010315 masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
static pascal void AsyncUDPNotifier( UDPsocket sock, OTEventCode code,
|
||||
OTResult result, void* cookie )
|
||||
{
|
||||
switch( code & 0x7f000000L)
|
||||
{
|
||||
case 0:
|
||||
sock->newEvent |= code;
|
||||
result = 0;
|
||||
break;
|
||||
case kCOMPLETEEVENT:
|
||||
if(!(code & 0x00FFFFE0 ))
|
||||
sock->newCompletion |= CompleteMask( code );
|
||||
if( code == T_OPENCOMPLETE )
|
||||
sock->channel = (SOCKET)(cookie);
|
||||
break;
|
||||
default:
|
||||
if( code != kOTProviderWillClose )
|
||||
result = 0;
|
||||
}
|
||||
// Do we need these ???? TODO
|
||||
// sock->SetAsyncMacError( result );
|
||||
// sock->Wakeup();
|
||||
|
||||
// Do we need to ?
|
||||
//YieldToAnyThread();
|
||||
}
|
||||
|
||||
/* Retrieve OT event */
|
||||
// This function is completely same as AsyncTCPPopEvent,
|
||||
// except for the argument, UDPsocket / TCPsocket
|
||||
// ( 010315 masahiro minami<elsur@aaa.letter.co.jp>)
|
||||
static void AsyncUDPPopEvent( UDPsocket sock )
|
||||
{
|
||||
// Make sure OT calls are not interrupted
|
||||
// Not sure if we really need this.
|
||||
OTEnterNotifier( sock->channel );
|
||||
|
||||
sock->event |= (sock->curEvent = sock->newEvent );
|
||||
sock->completion |= ( sock->curCompletion = sock->newCompletion );
|
||||
sock->newEvent = sock->newCompletion = 0;
|
||||
|
||||
OTLeaveNotifier( sock->channel );
|
||||
|
||||
if( sock->curEvent & T_UDERR)
|
||||
{
|
||||
// We just clear the error.
|
||||
// Should we feed this back to users ?
|
||||
// (TODO )
|
||||
OTRcvUDErr( sock->channel, NULL );
|
||||
}
|
||||
|
||||
// Remote is disconnecting...
|
||||
if( sock->curEvent & ( T_DISCONNECT | T_ORDREL ))
|
||||
{
|
||||
sock->readShutdown = true;
|
||||
}
|
||||
|
||||
if( sock->curEvent &T_CONNECT)
|
||||
{
|
||||
// Ignore the info of remote (second parameter).
|
||||
// Shoule we care ?
|
||||
// (TODO)
|
||||
OTRcvConnect( sock->channel, NULL );
|
||||
}
|
||||
|
||||
if( sock->curEvent & T_ORDREL )
|
||||
{
|
||||
OTRcvOrderlyDisconnect( sock->channel );
|
||||
}
|
||||
|
||||
if( sock->curEvent & T_DISCONNECT )
|
||||
{
|
||||
OTRcvDisconnect( sock->channel, NULL );
|
||||
}
|
||||
|
||||
// Should we ??
|
||||
// (010318 masahiro minami<elsur@aaa.letter.co.jp>
|
||||
//YieldToAnyThread();
|
||||
}
|
||||
|
||||
/* Create a new UDPsocket */
|
||||
// Because TCPsocket structure gets bigger and bigger,
|
||||
// I think we'd better have a constructor function and delete function.
|
||||
// ( 01/02/25 masahiro minami<elsur@aaa.letter.co.jp> )
|
||||
/*static*/ UDPsocket AsyncUDPNewSocket()
|
||||
{
|
||||
UDPsocket sock;
|
||||
|
||||
sock = (UDPsocket)malloc(sizeof(*sock));
|
||||
if ( sock == NULL ) {
|
||||
SDLNet_SetError("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->newEvent = 0;
|
||||
sock->event = 0;
|
||||
sock->curEvent = 0;
|
||||
sock->newCompletion = 0;
|
||||
sock->completion = 0;
|
||||
sock->curCompletion = 0;
|
||||
//sock->info = NULL;
|
||||
sock->readShutdown = sock->writeShutdown = false;
|
||||
sock->error = 0;
|
||||
sock->config = NULL;
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
|
||||
/* Allocate/free a single UDP packet 'size' bytes long.
|
||||
The new packet is returned, or NULL if the function ran out of memory.
|
||||
*/
|
||||
@@ -201,6 +64,7 @@ extern UDPpacket *SDLNet_AllocPacket(int size)
|
||||
}
|
||||
}
|
||||
if ( error ) {
|
||||
SDLNet_SetError("Out of memory");
|
||||
SDLNet_FreePacket(packet);
|
||||
packet = NULL;
|
||||
}
|
||||
@@ -248,6 +112,7 @@ UDPpacket **SDLNet_AllocPacketV(int howmany, int size)
|
||||
packetV[i] = NULL;
|
||||
|
||||
if ( i != howmany ) {
|
||||
SDLNet_SetError("Out of memory");
|
||||
SDLNet_FreePacketV(packetV);
|
||||
packetV = NULL;
|
||||
}
|
||||
@@ -272,12 +137,11 @@ void SDLNet_FreePacketV(UDPpacket **packetV)
|
||||
/* Open a UDP network socket
|
||||
If 'port' is non-zero, the UDP socket is bound to a fixed local port.
|
||||
*/
|
||||
extern UDPsocket SDLNet_UDP_Open(Uint16 port)
|
||||
UDPsocket SDLNet_UDP_Open(Uint16 port)
|
||||
{
|
||||
UDPsocket sock;
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
EndpointRef dummy = NULL;
|
||||
#endif
|
||||
struct sockaddr_in sock_addr;
|
||||
socklen_t sock_len;
|
||||
|
||||
/* Allocate a UDP socket structure */
|
||||
sock = (UDPsocket)malloc(sizeof(*sock));
|
||||
@@ -286,124 +150,91 @@ extern UDPsocket SDLNet_UDP_Open(Uint16 port)
|
||||
goto error_return;
|
||||
}
|
||||
memset(sock, 0, sizeof(*sock));
|
||||
memset(&sock_addr, 0, sizeof(sock_addr));
|
||||
|
||||
/* Open the socket */
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
{
|
||||
sock->error = OTAsyncOpenEndpoint(
|
||||
OTCreateConfiguration(kUDPName),0, &(sock->info),
|
||||
(OTNotifyProcPtr)AsyncUDPNotifier, sock );
|
||||
AsyncUDPPopEvent( sock );
|
||||
while( !sock->error && !( sock->completion & CompleteMask(T_OPENCOMPLETE)))
|
||||
{
|
||||
AsyncUDPPopEvent( sock );
|
||||
}
|
||||
if( sock->error )
|
||||
{
|
||||
SDLNet_SetError("Could not open UDP socket");
|
||||
goto error_return;
|
||||
}
|
||||
// Should we ??
|
||||
// (01/05/03 minami<elsur@aaa.letter.co.jp>
|
||||
OTSetBlocking( sock->channel );
|
||||
}
|
||||
#else
|
||||
sock->channel = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
|
||||
if ( sock->channel == INVALID_SOCKET )
|
||||
{
|
||||
SDLNet_SetError("Couldn't create socket");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
{
|
||||
InetAddress required, assigned;
|
||||
TBind req_addr, assigned_addr;
|
||||
OSStatus status;
|
||||
InetInterfaceInfo info;
|
||||
|
||||
memset(&assigned_addr, 0, sizeof(assigned_addr));
|
||||
assigned_addr.addr.maxlen = sizeof(assigned);
|
||||
assigned_addr.addr.len = sizeof(assigned);
|
||||
assigned_addr.addr.buf = (UInt8 *) &assigned;
|
||||
|
||||
if ( port ) {
|
||||
status = OTInetGetInterfaceInfo( &info, kDefaultInetInterface );
|
||||
if( status != kOTNoError )
|
||||
goto error_return;
|
||||
OTInitInetAddress(&required, port, info.fAddress );
|
||||
req_addr.addr.maxlen = sizeof( required );
|
||||
req_addr.addr.len = sizeof( required );
|
||||
req_addr.addr.buf = (UInt8 *) &required;
|
||||
|
||||
sock->error = OTBind(sock->channel, &req_addr, &assigned_addr);
|
||||
} else {
|
||||
sock->error = OTBind(sock->channel, nil, &assigned_addr );
|
||||
}
|
||||
AsyncUDPPopEvent(sock);
|
||||
|
||||
while( !sock->error && !(sock->completion & CompleteMask(T_BINDCOMPLETE)))
|
||||
{
|
||||
AsyncUDPPopEvent(sock);
|
||||
}
|
||||
if (sock->error != noErr)
|
||||
{
|
||||
SDLNet_SetError("Couldn't bind to local port, OTBind() = %d",(int) status);
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
sock->address.host = assigned.fHost;
|
||||
sock->address.port = assigned.fPort;
|
||||
|
||||
#ifdef DEBUG_NET
|
||||
printf("UDP open host = %d, port = %d\n", assigned.fHost, assigned.fPort );
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
/* Bind locally, if appropriate */
|
||||
if ( port )
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
memset(&sock_addr, 0, sizeof(sock_addr));
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
sock_addr.sin_port = SDL_SwapBE16(port);
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
sock_addr.sin_port = SDL_SwapBE16(port);
|
||||
|
||||
/* Bind the socket for listening */
|
||||
if ( bind(sock->channel, (struct sockaddr *)&sock_addr,
|
||||
sizeof(sock_addr)) == SOCKET_ERROR ) {
|
||||
SDLNet_SetError("Couldn't bind to local port");
|
||||
goto error_return;
|
||||
}
|
||||
/* Fill in the channel host address */
|
||||
sock->address.host = sock_addr.sin_addr.s_addr;
|
||||
sock->address.port = sock_addr.sin_port;
|
||||
/* Bind the socket for listening */
|
||||
if ( bind(sock->channel, (struct sockaddr *)&sock_addr,
|
||||
sizeof(sock_addr)) == SOCKET_ERROR ) {
|
||||
SDLNet_SetError("Couldn't bind to local port");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
/* Get the bound address and port */
|
||||
sock_len = sizeof(sock_addr);
|
||||
if ( getsockname(sock->channel, (struct sockaddr *)&sock_addr, &sock_len) < 0 ) {
|
||||
perror("getsockname");
|
||||
SDLNet_SetError("Couldn't get socket address");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
/* Fill in the channel host address */
|
||||
sock->address.host = sock_addr.sin_addr.s_addr;
|
||||
sock->address.port = sock_addr.sin_port;
|
||||
|
||||
#ifdef SO_BROADCAST
|
||||
/* Allow LAN broadcasts with the socket */
|
||||
{ int yes = 1;
|
||||
setsockopt(sock->channel, SOL_SOCKET, SO_BROADCAST, (char*)&yes, sizeof(yes));
|
||||
}
|
||||
#endif
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
#ifdef IP_ADD_MEMBERSHIP
|
||||
/* Receive LAN multicast packets on 224.0.0.1
|
||||
This automatically works on Mac OS X, Linux and BSD, but needs
|
||||
this code on Windows.
|
||||
*/
|
||||
/* A good description of multicast can be found here:
|
||||
http://www.docs.hp.com/en/B2355-90136/ch05s05.html
|
||||
*/
|
||||
/* FIXME: Add support for joining arbitrary groups to the API */
|
||||
{
|
||||
struct ip_mreq g;
|
||||
|
||||
g.imr_multiaddr.s_addr = inet_addr("224.0.0.1");
|
||||
g.imr_interface.s_addr = INADDR_ANY;
|
||||
setsockopt(sock->channel, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
||||
(char*)&g, sizeof(g));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The socket is ready */
|
||||
|
||||
return(sock);
|
||||
|
||||
error_return:
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
if( dummy )
|
||||
OTCloseProvider( dummy );
|
||||
#endif
|
||||
SDLNet_UDP_Close(sock);
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
void SDLNet_UDP_SetPacketLoss(UDPsocket sock, int percent)
|
||||
{
|
||||
/* FIXME: We may want this behavior to be reproducible
|
||||
but there isn't a portable reentrant random
|
||||
number generator with good randomness.
|
||||
*/
|
||||
srandom(SDL_GetTicks());
|
||||
|
||||
if (percent < 0) {
|
||||
percent = 0;
|
||||
} else if (percent > 100) {
|
||||
percent = 100;
|
||||
}
|
||||
sock->packetloss = percent;
|
||||
}
|
||||
|
||||
/* Verify that the channel is in the valid range */
|
||||
static int ValidChannel(int channel)
|
||||
{
|
||||
@@ -423,10 +254,15 @@ static int ValidChannel(int channel)
|
||||
address, to which all outbound packets on the channel are sent.
|
||||
This function returns the channel which was bound, or -1 on error.
|
||||
*/
|
||||
int SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address)
|
||||
int SDLNet_UDP_Bind(UDPsocket sock, int channel, const IPaddress *address)
|
||||
{
|
||||
struct UDP_channel *binding;
|
||||
|
||||
if ( sock == NULL ) {
|
||||
SDLNet_SetError("Passed a NULL socket");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( channel == -1 ) {
|
||||
for ( channel=0; channel < SDLNET_MAX_UDPCHANNELS; ++channel ) {
|
||||
binding = &sock->binding[channel];
|
||||
@@ -493,48 +329,33 @@ int SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets)
|
||||
int numsent, i, j;
|
||||
struct UDP_channel *binding;
|
||||
int status;
|
||||
#ifndef MACOS_OPENTRANSPORT
|
||||
int sock_len;
|
||||
struct sockaddr_in sock_addr;
|
||||
|
||||
if ( sock == NULL ) {
|
||||
SDLNet_SetError("Passed a NULL socket");
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Set up the variables to send packets */
|
||||
sock_len = sizeof(sock_addr);
|
||||
#endif
|
||||
|
||||
numsent = 0;
|
||||
for ( i=0; i<npackets; ++i )
|
||||
{
|
||||
/* Simulate packet loss, if desired */
|
||||
if (sock->packetloss) {
|
||||
if ((random()%100) <= sock->packetloss) {
|
||||
packets[i]->status = packets[i]->len;
|
||||
++numsent;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* if channel is < 0, then use channel specified in sock */
|
||||
|
||||
if ( packets[i]->channel < 0 )
|
||||
{
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
TUnitData OTpacket;
|
||||
InetAddress address;
|
||||
|
||||
memset(&OTpacket, 0, sizeof(OTpacket));
|
||||
OTpacket.addr.buf = (Uint8 *)&address;
|
||||
OTpacket.addr.len = (sizeof address);
|
||||
OTpacket.udata.buf = packets[i]->data;
|
||||
OTpacket.udata.len = packets[i]->len;
|
||||
OTInitInetAddress(&address, packets[i]->address.port, packets[i]->address.host);
|
||||
#ifdef DEBUG_NET
|
||||
printf("Packet send address: 0x%8.8x:%d, length = %d\n", packets[i]->address.host, packets[i]->address.port, packets[i]->len);
|
||||
#endif
|
||||
|
||||
status = OTSndUData(sock->channel, &OTpacket);
|
||||
#ifdef DEBUG_NET
|
||||
printf("SDLNet_UDP_SendV OTSndUData return value is ;%d\n", status );
|
||||
#endif
|
||||
|
||||
AsyncUDPPopEvent( sock );
|
||||
packets[i]->status = status;
|
||||
|
||||
if (status == noErr)
|
||||
{
|
||||
++numsent;
|
||||
}
|
||||
#else
|
||||
sock_addr.sin_addr.s_addr = packets[i]->address.host;
|
||||
sock_addr.sin_port = packets[i]->address.port;
|
||||
sock_addr.sin_family = AF_INET;
|
||||
@@ -546,7 +367,6 @@ int SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets)
|
||||
packets[i]->status = status;
|
||||
++numsent;
|
||||
}
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -559,33 +379,6 @@ int SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets)
|
||||
|
||||
for ( j=binding->numbound-1; j>=0; --j )
|
||||
{
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
TUnitData OTpacket;
|
||||
InetAddress address;
|
||||
|
||||
OTInitInetAddress(&address, binding->address[j].port,binding->address[j].host);
|
||||
#ifdef DEBUG_NET
|
||||
printf("Packet send address: 0x%8.8x:%d, length = %d\n", binding->address[j].host, binding->address[j].port, packets[i]->len);
|
||||
#endif
|
||||
memset(&OTpacket, 0, sizeof(OTpacket));
|
||||
OTpacket.addr.buf = (Uint8 *)&address;
|
||||
OTpacket.addr.len = (sizeof address);
|
||||
OTpacket.udata.buf = packets[i]->data;
|
||||
OTpacket.udata.len = packets[i]->len;
|
||||
|
||||
status = OTSndUData(sock->channel, &OTpacket);
|
||||
#ifdef DEBUG_NET
|
||||
printf("SDLNet_UDP_SendV OTSndUData returne value is;%d\n", status );
|
||||
#endif
|
||||
AsyncUDPPopEvent(sock);
|
||||
packets[i]->status = status;
|
||||
|
||||
if (status == noErr)
|
||||
{
|
||||
++numsent;
|
||||
}
|
||||
|
||||
#else
|
||||
sock_addr.sin_addr.s_addr = binding->address[j].host;
|
||||
sock_addr.sin_port = binding->address[j].port;
|
||||
sock_addr.sin_family = AF_INET;
|
||||
@@ -597,7 +390,6 @@ int SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets)
|
||||
packets[i]->status = status;
|
||||
++numsent;
|
||||
}
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -616,35 +408,12 @@ int SDLNet_UDP_Send(UDPsocket sock, int channel, UDPpacket *packet)
|
||||
static int SocketReady(SOCKET sock)
|
||||
{
|
||||
int retval = 0;
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
OTResult status;
|
||||
#else
|
||||
struct timeval tv;
|
||||
fd_set mask;
|
||||
#endif
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
//status = OTGetEndpointState(sock);
|
||||
status = OTLook(sock);
|
||||
if( status > 0 )
|
||||
retval = 1;
|
||||
|
||||
/* switch( status )
|
||||
{
|
||||
// case T_IDLE:
|
||||
case T_DATAXFER:
|
||||
// case T_INREL:
|
||||
retval = 1;
|
||||
break;
|
||||
default:
|
||||
OTCountDataBytes( sock, &numBytes );
|
||||
if( numBytes )
|
||||
retval = 1;
|
||||
}*/
|
||||
#else
|
||||
/* Check the file descriptors for available data */
|
||||
do {
|
||||
errno = 0;
|
||||
SDLNet_SetLastError(0);
|
||||
|
||||
/* Set up the mask of file descriptors */
|
||||
FD_ZERO(&mask);
|
||||
@@ -656,8 +425,7 @@ static int SocketReady(SOCKET sock)
|
||||
|
||||
/* Look! */
|
||||
retval = select(sock+1, &mask, NULL, NULL, &tv);
|
||||
} while ( errno == EINTR );
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
} while ( SDLNet_GetLastError() == EINTR );
|
||||
|
||||
return(retval == 1);
|
||||
}
|
||||
@@ -673,61 +441,29 @@ extern int SDLNet_UDP_RecvV(UDPsocket sock, UDPpacket **packets)
|
||||
{
|
||||
int numrecv, i, j;
|
||||
struct UDP_channel *binding;
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
TUnitData OTpacket;
|
||||
OTFlags flags;
|
||||
InetAddress address;
|
||||
#else
|
||||
int sock_len;
|
||||
socklen_t sock_len;
|
||||
struct sockaddr_in sock_addr;
|
||||
#endif
|
||||
|
||||
if ( sock == NULL ) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
numrecv = 0;
|
||||
while ( packets[numrecv] && SocketReady(sock->channel) )
|
||||
{
|
||||
UDPpacket *packet;
|
||||
UDPpacket *packet;
|
||||
|
||||
packet = packets[numrecv];
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
memset(&OTpacket, 0, sizeof(OTpacket));
|
||||
OTpacket.addr.buf = (Uint8 *)&address;
|
||||
OTpacket.addr.maxlen = (sizeof address);
|
||||
OTpacket.udata.buf = packet->data;
|
||||
OTpacket.udata.maxlen = packet->maxlen;
|
||||
|
||||
packet->status = OTRcvUData(sock->channel, &OTpacket, &flags);
|
||||
#ifdef DEBUG_NET
|
||||
printf("Packet status: %d\n", packet->status);
|
||||
#endif
|
||||
AsyncUDPPopEvent(sock);
|
||||
if (packet->status == noErr)
|
||||
{
|
||||
packet->len = OTpacket.udata.len;
|
||||
packet->address.host = address.fHost;
|
||||
packet->address.port = address.fPort;
|
||||
#ifdef DEBUG_NET
|
||||
printf("Packet address: 0x%8.8x:%d, length = %d\n", packet->address.host, packet->address.port, packet->len);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
sock_len = sizeof(sock_addr);
|
||||
packet->status = recvfrom(sock->channel,
|
||||
packet->data, packet->maxlen, 0,
|
||||
(struct sockaddr *)&sock_addr,
|
||||
#ifdef USE_GUSI_SOCKETS
|
||||
(unsigned int *)&sock_len);
|
||||
#else
|
||||
&sock_len);
|
||||
#endif
|
||||
if ( packet->status >= 0 ) {
|
||||
packet->len = packet->status;
|
||||
packet->address.host = sock_addr.sin_addr.s_addr;
|
||||
packet->address.port = sock_addr.sin_port;
|
||||
}
|
||||
#endif
|
||||
if (packet->status >= 0)
|
||||
{
|
||||
packet->channel = -1;
|
||||
|
||||
for (i=(SDLNET_MAX_UDPCHANNELS-1); i>=0; --i )
|
||||
@@ -783,12 +519,7 @@ extern void SDLNet_UDP_Close(UDPsocket sock)
|
||||
{
|
||||
if ( sock->channel != INVALID_SOCKET )
|
||||
{
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
OTUnbind(sock->channel);
|
||||
OTCloseProvider(sock->channel);
|
||||
#else
|
||||
closesocket(sock->channel);
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
}
|
||||
|
||||
free(sock);
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2004 Sam Lantinga
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id: SDLnetselect.c 1192 2004-01-04 17:41:55Z slouken $ */
|
||||
/* $Id$ */
|
||||
|
||||
#include "SDLnetsys.h"
|
||||
#include "SDL_net.h"
|
||||
@@ -30,9 +29,6 @@
|
||||
struct SDLNet_Socket {
|
||||
int ready;
|
||||
SOCKET channel;
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
OTEventCode curEvent;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _SDLNet_SocketSet {
|
||||
@@ -111,64 +107,6 @@ int SDLNet_DelSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock)
|
||||
first. This function returns the number of sockets ready for reading,
|
||||
or -1 if there was an error with the select() system call.
|
||||
*/
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
|
||||
{
|
||||
Uint32 stop;
|
||||
int numReady;
|
||||
|
||||
/* Loop, polling the network devices */
|
||||
|
||||
stop = SDL_GetTicks() + timeout;
|
||||
|
||||
do
|
||||
{
|
||||
OTResult status;
|
||||
size_t numBytes;
|
||||
int i;
|
||||
|
||||
numReady = 0;
|
||||
|
||||
for (i = set->numsockets-1;i >= 0;--i)
|
||||
{
|
||||
status = OTLook( set->sockets[i]->channel );
|
||||
if( status > 0 )
|
||||
{
|
||||
switch( status )
|
||||
{
|
||||
case T_UDERR:
|
||||
OTRcvUDErr( set->sockets[i]->channel , nil);
|
||||
break;
|
||||
case T_DISCONNECT:
|
||||
OTRcvDisconnect( set->sockets[i]->channel, nil );
|
||||
break;
|
||||
case T_ORDREL:
|
||||
OTRcvOrderlyDisconnect(set->sockets[i]->channel );
|
||||
break;
|
||||
case T_CONNECT:
|
||||
OTRcvConnect( set->sockets[i]->channel, nil );
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
set->sockets[i]->ready = 1;
|
||||
++numReady;
|
||||
}
|
||||
}
|
||||
else if( OTCountDataBytes(set->sockets[i]->channel, &numBytes ) != kOTNoDataErr )
|
||||
{
|
||||
set->sockets[i]->ready = 1;
|
||||
++numReady;
|
||||
}
|
||||
else
|
||||
set->sockets[i]->ready = 0;
|
||||
}
|
||||
|
||||
} while (!numReady && (SDL_GetTicks() < stop));
|
||||
|
||||
return(numReady);
|
||||
}
|
||||
#else
|
||||
int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
|
||||
{
|
||||
int i;
|
||||
@@ -187,7 +125,7 @@ int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
|
||||
|
||||
/* Check the file descriptors for available data */
|
||||
do {
|
||||
errno = 0;
|
||||
SDLNet_SetLastError(0);
|
||||
|
||||
/* Set up the mask of file descriptors */
|
||||
FD_ZERO(&mask);
|
||||
@@ -201,7 +139,7 @@ int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
|
||||
|
||||
/* Look! */
|
||||
retval = select(maxfd+1, &mask, NULL, NULL, &tv);
|
||||
} while ( errno == EINTR );
|
||||
} while ( SDLNet_GetLastError() == EINTR );
|
||||
|
||||
/* Mark all file descriptors ready that have data available */
|
||||
if ( retval > 0 ) {
|
||||
@@ -213,8 +151,7 @@ int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
#endif /* MACOS_OPENTRANSPORT */
|
||||
|
||||
|
||||
/* Free a set of sockets allocated by SDL_NetAllocSocketSet() */
|
||||
extern void SDLNet_FreeSocketSet(SDLNet_SocketSet set)
|
||||
{
|
||||
|
||||
@@ -1,53 +1,54 @@
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2004 Sam Lantinga
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id: SDLnetsys.h 1720 2005-11-23 07:57:10Z icculus $ */
|
||||
/* $Id$ */
|
||||
|
||||
/* Include normal system headers */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef macintosh
|
||||
#ifndef USE_GUSI_SOCKETS
|
||||
#define MACOS_OPENTRANSPORT
|
||||
//#error Open Transport driver is broken
|
||||
#ifndef _WIN32_WCE
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#endif /* macintosh */
|
||||
|
||||
/* Include system network headers */
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTptInternet.h>
|
||||
#else
|
||||
#if defined(__WIN32__) || defined(WIN32)
|
||||
#define __USE_W32_SOCKETS
|
||||
#include <windows.h>
|
||||
#ifdef _WIN64
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <winsock.h>
|
||||
/* NOTE: windows socklen_t is signed
|
||||
* and is defined only for winsock2. */
|
||||
typedef int socklen_t;
|
||||
#endif /* W64 */
|
||||
#include <iphlpapi.h>
|
||||
#else /* UNIX */
|
||||
#ifdef __OS2__
|
||||
#include <types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@@ -58,18 +59,17 @@
|
||||
#ifdef linux /* FIXME: what other platforms have this? */
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <netdb.h>
|
||||
#endif /* WIN32 */
|
||||
#endif /* Open Transport */
|
||||
|
||||
/* FIXME: What platforms need this? */
|
||||
#if 0
|
||||
typedef Uint32 socklen_t;
|
||||
#endif
|
||||
|
||||
/* System-dependent definitions */
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
//#define closesocket OTCloseProvider
|
||||
#define closesocket OTSndOrderlyDisconnect
|
||||
#define SOCKET EndpointRef
|
||||
#define INVALID_SOCKET kOTInvalidEndpointRef
|
||||
#else
|
||||
#ifndef __USE_W32_SOCKETS
|
||||
#ifdef __OS2__
|
||||
#define closesocket soclose
|
||||
@@ -80,5 +80,15 @@
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#endif /* __USE_W32_SOCKETS */
|
||||
#endif /* Open Transport */
|
||||
|
||||
#ifdef __USE_W32_SOCKETS
|
||||
#define SDLNet_GetLastError WSAGetLastError
|
||||
#define SDLNet_SetLastError WSASetLastError
|
||||
#ifndef EINTR
|
||||
#define EINTR WSAEINTR
|
||||
#endif
|
||||
#else
|
||||
int SDLNet_GetLastError(void);
|
||||
void SDLNet_SetLastError(int err);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2004 Sam Lantinga
|
||||
SDL_net: An example cross-platform network library for use with SDL
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id: SDL_net.h 3281 2007-07-15 05:58:56Z slouken $ */
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef _SDL_NET_H
|
||||
#define _SDL_NET_H
|
||||
@@ -41,7 +40,7 @@ extern "C" {
|
||||
*/
|
||||
#define SDL_NET_MAJOR_VERSION 1
|
||||
#define SDL_NET_MINOR_VERSION 2
|
||||
#define SDL_NET_PATCHLEVEL 7
|
||||
#define SDL_NET_PATCHLEVEL 9
|
||||
|
||||
/* This macro can be used to fill a version structure with the compile-time
|
||||
* version of the SDL_net library.
|
||||
@@ -87,6 +86,9 @@ typedef struct {
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xFFFFFFFF
|
||||
#endif
|
||||
#ifndef INADDR_LOOPBACK
|
||||
#define INADDR_LOOPBACK 0x7f000001
|
||||
#endif
|
||||
#ifndef INADDR_BROADCAST
|
||||
#define INADDR_BROADCAST 0xFFFFFFFF
|
||||
#endif
|
||||
@@ -97,8 +99,12 @@ extern DECLSPEC int SDLCALL SDLNet_ResolveHost(IPaddress *address, const char *h
|
||||
otherwise a pointer to a static buffer containing the hostname
|
||||
is returned. Note that this function is not thread-safe.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDLNet_ResolveIP(IPaddress *ip);
|
||||
extern DECLSPEC const char * SDLCALL SDLNet_ResolveIP(const IPaddress *ip);
|
||||
|
||||
/* Get the addresses of network interfaces on this system.
|
||||
This returns the number of addresses saved in 'addresses'
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDLNet_GetLocalAddresses(IPaddress *addresses, int maxcount);
|
||||
|
||||
/***********************************************************************/
|
||||
/* TCP network API */
|
||||
@@ -189,6 +195,10 @@ extern DECLSPEC void SDLCALL SDLNet_FreePacketV(UDPpacket **packetV);
|
||||
*/
|
||||
extern DECLSPEC UDPsocket SDLCALL SDLNet_UDP_Open(Uint16 port);
|
||||
|
||||
/* Set the percentage of simulated packet loss for packets sent on the socket.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDLNet_UDP_SetPacketLoss(UDPsocket sock, int percent);
|
||||
|
||||
/* Bind the address 'address' to the requested channel on the UDP socket.
|
||||
If the channel is -1, then the first unbound channel will be bound with
|
||||
the given address as it's primary address.
|
||||
@@ -198,7 +208,7 @@ extern DECLSPEC UDPsocket SDLCALL SDLNet_UDP_Open(Uint16 port);
|
||||
address, to which all outbound packets on the channel are sent.
|
||||
This function returns the channel which was bound, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address);
|
||||
extern DECLSPEC int SDLCALL SDLNet_UDP_Bind(UDPsocket sock, int channel, const IPaddress *address);
|
||||
|
||||
/* Unbind all addresses from the given channel */
|
||||
extern DECLSPEC void SDLCALL SDLNet_UDP_Unbind(UDPsocket sock, int channel);
|
||||
@@ -269,7 +279,7 @@ extern DECLSPEC void SDLCALL SDLNet_UDP_Close(UDPsocket sock);
|
||||
typedef struct _SDLNet_SocketSet *SDLNet_SocketSet;
|
||||
|
||||
/* Any network socket can be safely cast to this socket type */
|
||||
typedef struct {
|
||||
typedef struct _SDLNet_GenericSocket {
|
||||
int ready;
|
||||
} *SDLNet_GenericSocket;
|
||||
|
||||
@@ -281,16 +291,16 @@ extern DECLSPEC SDLNet_SocketSet SDLCALL SDLNet_AllocSocketSet(int maxsockets);
|
||||
|
||||
/* Add a socket to a set of sockets to be checked for available data */
|
||||
#define SDLNet_TCP_AddSocket(set, sock) \
|
||||
SDLNet_AddSocket(set, (SDLNet_GenericSocket)sock)
|
||||
SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
|
||||
#define SDLNet_UDP_AddSocket(set, sock) \
|
||||
SDLNet_AddSocket(set, (SDLNet_GenericSocket)sock)
|
||||
SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
|
||||
extern DECLSPEC int SDLCALL SDLNet_AddSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock);
|
||||
|
||||
/* Remove a socket from a set of sockets to be checked for available data */
|
||||
#define SDLNet_TCP_DelSocket(set, sock) \
|
||||
SDLNet_DelSocket(set, (SDLNet_GenericSocket)sock)
|
||||
SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
|
||||
#define SDLNet_UDP_DelSocket(set, sock) \
|
||||
SDLNet_DelSocket(set, (SDLNet_GenericSocket)sock)
|
||||
SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
|
||||
extern DECLSPEC int SDLCALL SDLNet_DelSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock);
|
||||
|
||||
/* This function checks to see if data is available for reading on the
|
||||
@@ -307,7 +317,7 @@ extern DECLSPEC int SDLCALL SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 tim
|
||||
for reading.
|
||||
*/
|
||||
#define SDLNet_SocketReady(sock) \
|
||||
((sock != NULL) && ((SDLNet_GenericSocket)sock)->ready)
|
||||
((sock != NULL) && SDL_reinterpret_cast(SDLNet_GenericSocket, sock)->ready)
|
||||
|
||||
/* Free a set of sockets allocated by SDL_NetAllocSocketSet() */
|
||||
extern DECLSPEC void SDLCALL SDLNet_FreeSocketSet(SDLNet_SocketSet set);
|
||||
@@ -344,7 +354,7 @@ extern no_parse_DECLSPEC char * SDLCALL SDLNet_GetError(void);
|
||||
/* Inline macro functions to read/write network data */
|
||||
|
||||
/* Warning, some systems have data access alignment restrictions */
|
||||
#if defined(sparc) || defined(mips)
|
||||
#if defined(sparc) || defined(mips) || defined(__arm__)
|
||||
#define SDL_DATA_ALIGNED 1
|
||||
#endif
|
||||
#ifndef SDL_DATA_ALIGNED
|
||||
@@ -354,87 +364,52 @@ extern no_parse_DECLSPEC char * SDLCALL SDLNet_GetError(void);
|
||||
/* Write a 16 bit value to network packet buffer */
|
||||
#if !SDL_DATA_ALIGNED
|
||||
#define SDLNet_Write16(value, areap) \
|
||||
(*(Uint16 *)(areap) = SDL_SwapBE16(value))
|
||||
(*SDL_reinterpret_cast(Uint16 *, areap) = SDL_SwapBE16(value))
|
||||
#else
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#define SDLNet_Write16(value, areap) \
|
||||
do \
|
||||
{ \
|
||||
Uint8 *area = (Uint8 *)(areap); \
|
||||
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
|
||||
area[0] = (value >> 8) & 0xFF; \
|
||||
area[1] = value & 0xFF; \
|
||||
} while ( 0 )
|
||||
#else
|
||||
#define SDLNet_Write16(value, areap) \
|
||||
do \
|
||||
{ \
|
||||
Uint8 *area = (Uint8 *)(areap); \
|
||||
area[1] = (value >> 8) & 0xFF; \
|
||||
area[0] = value & 0xFF; \
|
||||
} while ( 0 )
|
||||
#endif
|
||||
#endif /* !SDL_DATA_ALIGNED */
|
||||
|
||||
/* Write a 32 bit value to network packet buffer */
|
||||
#if !SDL_DATA_ALIGNED
|
||||
#define SDLNet_Write32(value, areap) \
|
||||
*(Uint32 *)(areap) = SDL_SwapBE32(value);
|
||||
*SDL_reinterpret_cast(Uint32 *, areap) = SDL_SwapBE32(value);
|
||||
#else
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#define SDLNet_Write32(value, areap) \
|
||||
do \
|
||||
{ \
|
||||
Uint8 *area = (Uint8 *)(areap); \
|
||||
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
|
||||
area[0] = (value >> 24) & 0xFF; \
|
||||
area[1] = (value >> 16) & 0xFF; \
|
||||
area[2] = (value >> 8) & 0xFF; \
|
||||
area[3] = value & 0xFF; \
|
||||
} while ( 0 )
|
||||
#else
|
||||
#define SDLNet_Write32(value, areap) \
|
||||
do \
|
||||
{ \
|
||||
Uint8 *area = (Uint8 *)(areap); \
|
||||
area[3] = (value >> 24) & 0xFF; \
|
||||
area[2] = (value >> 16) & 0xFF; \
|
||||
area[1] = (value >> 8) & 0xFF; \
|
||||
area[0] = value & 0xFF; \
|
||||
} while ( 0 )
|
||||
#endif
|
||||
#endif /* !SDL_DATA_ALIGNED */
|
||||
|
||||
/* Read a 16 bit value from network packet buffer */
|
||||
#if !SDL_DATA_ALIGNED
|
||||
#define SDLNet_Read16(areap) \
|
||||
(SDL_SwapBE16(*(Uint16 *)(areap)))
|
||||
#else
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#define SDLNet_Read16(areap) \
|
||||
((((Uint8 *)areap)[0] << 8) | ((Uint8 *)areap)[1] << 0)
|
||||
(SDL_SwapBE16(*SDL_reinterpret_cast(Uint16 *, areap)))
|
||||
#else
|
||||
#define SDLNet_Read16(areap) \
|
||||
((((Uint8 *)areap)[1] << 8) | ((Uint8 *)areap)[0] << 0)
|
||||
#endif
|
||||
(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[1] << 0)
|
||||
#endif /* !SDL_DATA_ALIGNED */
|
||||
|
||||
/* Read a 32 bit value from network packet buffer */
|
||||
#if !SDL_DATA_ALIGNED
|
||||
#define SDLNet_Read32(areap) \
|
||||
(SDL_SwapBE32(*(Uint32 *)(areap)))
|
||||
#else
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#define SDLNet_Read32(areap) \
|
||||
((((Uint8 *)areap)[0] << 24) | (((Uint8 *)areap)[1] << 16) | \
|
||||
(((Uint8 *)areap)[2] << 8) | ((Uint8 *)areap)[3] << 0)
|
||||
(SDL_SwapBE32(*SDL_reinterpret_cast(Uint32 *, areap)))
|
||||
#else
|
||||
#define SDLNet_Read32(areap) \
|
||||
((((Uint8 *)areap)[3] << 24) | (((Uint8 *)areap)[2] << 16) | \
|
||||
(((Uint8 *)areap)[1] << 8) | ((Uint8 *)areap)[0] << 0)
|
||||
#endif
|
||||
(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[1] << 16) | \
|
||||
((SDL_reinterpret_cast(Uint8 *, areap))[2] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[3] << 0)
|
||||
#endif /* !SDL_DATA_ALIGNED */
|
||||
|
||||
#ifdef MACOS_OPENTRANSPORT
|
||||
#endif
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user