mail[Wesnoth-commits] r33199 - in /trunk: changelog src/network.cpp src/network_worker.cpp src/network_worker.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by koraq on March 01, 2009 - 08:43:
Author: mordante
Date: Sun Mar  1 08:43:22 2009
New Revision: 33199

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33199&view=rev
Log:
Align all network buffers on 4 bytes.

Just to make sure we won't get another SIGBUS on the Sparc.

Modified:
    trunk/changelog
    trunk/src/network.cpp
    trunk/src/network_worker.cpp
    trunk/src/network_worker.hpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=33199&r1=33198&r2=33199&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Mar  1 08:43:22 2009
@@ -18,6 +18,8 @@
  * WML Engine:
    * Fix incorrect or doubled "sighted" events when delaying shroud update.
    * Fix sometimes doubled "select" events.
+ * Miscellaneous and bug fixes:
+   * Align all network buffers on 4 bytes
 
 Version 1.5.11:
  * Campaigns:

Modified: trunk/src/network.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network.cpp?rev=33199&r1=33198&r2=33199&view=diff
==============================================================================
--- trunk/src/network.cpp (original)
+++ trunk/src/network.cpp Sun Mar  1 08:43:22 2009
@@ -428,7 +428,7 @@
        }
 
        // Send data telling the remote host that this is a new connection
-       char buf[4];
+       char buf[4] ALIGN_4;
        SDLNet_Write32(0,buf);
        const int nbytes = SDLNet_TCP_Send(sock,buf,4);
        if(nbytes != 4) {
@@ -542,7 +542,7 @@
 
                // Receive the 4 bytes telling us if they're a new connection
                // or trying to recover a connection
-               char buf[4];
+               char buf[4] ALIGN_4;
 
                const TCPsocket sock = *i;
                SDLNet_TCP_DelSocket(pending_socket_set,sock);
@@ -699,7 +699,7 @@
                        // See if this socket is still waiting for it to be 
assigned its remote handle.
                        // If it is, then the first 4 bytes must be the 
remote handle.
                        if(is_pending_remote_handle(*i)) {
-                               char buf[4];
+                               char buf[4] ALIGN_4;
                                int len = SDLNet_TCP_Recv(sock,buf,4);
                                if(len != 4) {
                                        throw error("Remote host 
disconnected",*i);
@@ -809,7 +809,7 @@
                        // See if this socket is still waiting for it to be 
assigned its remote handle.
                        // If it is, then the first 4 bytes must be the 
remote handle.
                        if(is_pending_remote_handle(*i)) {
-                               char buf[4];
+                               char buf[4] ALIGN_4;
                                int len = SDLNet_TCP_Recv(sock,buf,4);
                                if(len != 4) {
                                        throw error("Remote host 
disconnected",*i);

Modified: trunk/src/network_worker.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.cpp?rev=33199&r1=33198&r2=33199&view=diff
==============================================================================
--- trunk/src/network_worker.cpp (original)
+++ trunk/src/network_worker.cpp Sun Mar  1 08:43:22 2009
@@ -607,15 +607,7 @@
 
 static SOCKET_STATE receive_buf(TCPsocket sock, std::vector<char>& buf)
 {
-#ifdef __GNUC__
-       // The address needs to be aligned on a Sparc system, if it's not 
aligned
-       // the SDLNet_Read32 call will cause a SIGBUS and the server will be
-       // terminated.
-       // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=426318
-       char num_buf[4] __attribute__ ((aligned (4)));
-#else
-       char num_buf[4];
-#endif
+       char num_buf[4] ALIGN_4;
        bool res = receive_with_timeout(sock,num_buf,4,false);
 
        if(!res) {

Modified: trunk/src/network_worker.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.hpp?rev=33199&r1=33198&r2=33199&view=diff
==============================================================================
--- trunk/src/network_worker.hpp (original)
+++ trunk/src/network_worker.hpp Sun Mar  1 08:43:22 2009
@@ -29,6 +29,21 @@
 #include "config.hpp"
 #include "network.hpp"
 #include "SDL_net.h"
+
+/**
+ * Aligns a variable on a 4 byte boundry.
+ *
+ * The address needs to be aligned on a Sparc system, if it's not aligned the
+ * SDLNet_Read32 call will cause a SIGBUS and the server will be terminated 
[1].
+ * Best use this alignment for all buffers used in for the SDL_Net calls.
+ *
+ * [1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=426318
+ */
+#ifdef __GNUC__
+#define ALIGN_4 __attribute__ ((aligned (4)))
+#else
+#define ALIGN_4 
+#endif
 
 namespace network_worker_pool
 {




Related Messages


Powered by MHonArc, Updated Sun Mar 01 09:00:06 2009