aboutsummaryrefslogtreecommitdiffstats
path: root/toolchain/gcc/patches/4.3.3+cs/820-libgcc_pic.patch
Commit message (Expand)AuthorAgeFilesLines
* nuke support for older gcc versions, except for 4.4.6 (needed for avr32 and u...Imre Kaloz2011-07-021-36/+0
* gcc: backport libgcc_pic changes to older gcc4 versions, install the libgcc m...Felix Fietkau2009-10-201-1/+1
* gcc: create a proper libgcc_pic.a static library for relinking (4.3.3+ for no...Felix Fietkau2009-10-191-0/+36
> 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
#============================================================================
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#============================================================================
# Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
#============================================================================

import sys
import threading
import select
import socket
import fcntl

from errno import EAGAIN, EINTR, EWOULDBLOCK

"""General classes to support server and client sockets, without
specifying what kind of socket they are. There are subclasses
for TCP and unix-domain sockets (see tcp.py and unix.py).
"""

"""We make sockets non-blocking so that operations like accept()
don't block. We also select on a timeout. Otherwise we have no way
of getting the threads to shutdown.
"""
SELECT_TIMEOUT = 2.0

class SocketServerConnection:
    """An accepted connection to a server.
    """

    def __init__(self, sock, protocol, addr, server):
        self.sock = sock
        self.protocol = protocol
        self.addr = addr
        self.server = server
        self.buffer_n = 1024
        self.thread = None
        self.connected = True
        protocol.setTransport(self)
        protocol.connectionMade(addr)

    def run(self):
        self.thread = threading.Thread(target=self.main)
        #self.thread.setDaemon(True)
        self.thread.start()

    def main(self):
        while True:
            if not self.thread: break
            if self.select(): break
            if not self.thread: break
            data = self.read()
            if data is None: continue
            if data is True: break
            if self.dataReceived(data): break

    def select(self):
        try:
            select.select([self.sock], [], [], SELECT_TIMEOUT)
            return False
        except socket.error, ex:
            if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                return False
            else:
                self.loseConnection(ex)
                return True

    def read(self):
        try:
            data = self.sock.recv(self.buffer_n)
            if data == '':
                self.loseConnection()
                return True
            return data
        except socket.error, ex:
            if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                return None
            else:
                self.loseConnection(ex)
                return True

    def dataReceived(self, data):
        if not self.connected:
            return True
        if not self.protocol:
            return True
        try:
            self.protocol.dataReceived(data)
        except SystemExit:
            raise
        except Exception, ex:
            self.loseConnection(ex)
            return True
        return False

    def write(self, data):
        self.sock.send(data)

    def loseConnection(self, reason=None):
        self.thread = None
        self.closeSocket(reason)
        self.closeProtocol(reason)

    def closeSocket(self, reason):
        try:
            self.sock.close()
        except SystemExit:
            raise
        except:
            pass

    def closeProtocol(self, reason):
        try:
            if self.connected:
                self.connected = False
                if self.protocol:
                    self.protocol.connectionLost(reason)
        except SystemExit:
            raise
        except:
            pass

    def getHost(self):
        return self.sock.getsockname()

    def getPeer(self):
        return self.addr

class SocketListener:
    """A server socket, running listen in a thread.
    Accepts connections and runs a thread for each one.
    """

    def __init__(self, factory, backlog=None):
        if backlog is None:
            backlog = 5
        self.factory = factory
        self.sock = None
        self.backlog = backlog
        self.thread = None

    def createSocket(self):
        raise NotImplementedError()

    def setCloExec(self):
        fcntl.fcntl(self.sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)

    def acceptConnection(self, sock, protocol, addr):
        return SocketServerConnection(sock, protocol, addr, self)

    def startListening(self):
        if self.sock or self.thread:
            raise IOError("already listening")
        self.sock = self.createSocket()
        self.sock.setblocking(0)
        self.sock.listen(self.backlog)
        self.run()

    def stopListening(self, reason=None):
        self.loseConnection(reason)

    def run(self):
        self.factory.doStart()
        self.thread = threading.Thread(target=self.main)
        #self.thread.setDaemon(True)
        self.thread.start()

    def main(self):
        while True:
            if not self.thread: break
            if self.select(): break
            if self.accept(): break

    def select(self):
        try:
            select.select([self.sock], [], [], SELECT_TIMEOUT)
            return False
        except socket.error, ex:
            if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                return False
            else:
                self.loseConnection(ex)
                return True

    def accept(self):
        try:
            (sock, addr) = self.sock.accept()
            sock.setblocking(0)
            return self.accepted(sock, addr)
        except socket.error, ex:
            if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                return False
            else:
                self.loseConnection(ex)
                return True

    def accepted(self, sock, addr):
        protocol = self.factory.buildProtocol(addr)
        if protocol is None:
            self.loseConnection()
            return True
        connection = self.acceptConnection(sock, protocol, addr)
        connection.run()
        return False

    def loseConnection(self, reason=None):
        self.thread = None
        self.closeSocket(reason)
        self.closeFactory(reason)

    def closeSocket(self, reason):
        try:
            self.sock.close()
        except SystemExit:
            raise
        except Exception, ex:
            pass

    def closeFactory(self, reason):
        try:
            self.factory.doStop()
        except SystemExit:
            raise
        except:
            pass

class SocketClientConnection:
    """A connection to a server from a client.

    Call connectionMade() on the protocol in a thread when connected.
    It is completely up to the protocol what to do.
    """

    def __init__(self, connector):
        self.addr = None
        self.connector = connector
        self.buffer_n = 1024
        self.connected = False

    def createSocket (self):
        raise NotImplementedError()

    def write(self, data):
        if self.sock:
            return self.sock.send(data)
        else:
            return 0

    def connect(self, timeout):
        #todo: run a timer to cancel on timeout?
        try:
            sock = self.createSocket()
            sock.connect(self.addr)
            self.sock = sock
            self.connected = True
            self.protocol = self.connector.buildProtocol(self.addr)
            self.protocol.setTransport(self)
        except SystemExit:
            raise
        except Exception, ex:
            self.connector.connectionFailed(ex)
            return False

        self.thread = threading.Thread(target=self.main)
        #self.thread.setDaemon(True)
        self.thread.start()
        return True

    def main(self):
        try:
            # Call the protocol in a thread.
            # Up to it what to do.
            self.protocol.connectionMade(self.addr)
        except SystemExit:
            raise
        except Exception, ex:
            self.loseConnection(ex)

    def mainLoop(self):
        # Something a protocol could call.
        while True:
            if not self.thread: break
            if self.select(): break
            if not self.thread: break
            data = self.read()
            if data is None: continue
            if data is True: break
            if self.dataReceived(data): break

    def select(self):
        try:
            select.select([self.sock], [], [], SELECT_TIMEOUT)
            return False
        except socket.error, ex:
            if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                return False
            else:
                self.loseConnection(ex)
                return True

    def read(self):
        try:
            data = self.sock.recv(self.buffer_n)
            return data
        except socket.error, ex:
            if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                return None
            else:
                self.loseConnection(ex)
                return True
        
    def dataReceived(self, data):
        if not self.protocol:
            return True
        try:
            self.protocol.dataReceived(data)
        except SystemExit:
            raise
        except Exception, ex:
            self.loseConnection(ex)
            return True
        return False

    def loseConnection(self, reason=None):
        self.thread = None
        self.closeSocket(reason)
        self.closeProtocol(reason)
        self.closeConnector(reason)

    def closeSocket(self, reason):
        try:
            if self.sock:
                self.sock.close()
        except SystemExit:
            raise
        except:
            pass

    def closeProtocol(self, reason):
        try:
            if self.connected:
                self.connected = False
                if self.protocol:
                    self.protocol.connectionLost(reason)
        except SystemExit:
            raise
        except:
            pass
        self.protocol = None

    def closeConnector(self, reason):
        try:
            self.connector.connectionLost(reason)
        except SystemExit:
            raise
        except:
            pass
        
class SocketConnector:
    """A client socket. Connects to a server and runs the client protocol
    in a thread.
    """

    def __init__(self, factory):
        self.factoryStarted = False
        self.clientLost = False
        self.clientFailed = False
        self.factory = factory
        self.state = "disconnected"
        self.transport = None

    def connectTransport(self):
        raise NotImplementedError()

    def connect(self):
        if self.state != "disconnected":
            raise socket.error(EINVAL, "cannot connect in state " + self.state)
        self.state = "connecting"
        self.clientLost = False
        self.clientFailed = False
        if not self.factoryStarted:
            self.factoryStarted = True
            self.factory.doStart()
        self.factory.startedConnecting(self)
        self.connectTransport()
        self.state = "connected"

    def stopConnecting(self):
        if self.state != "connecting":
            return
        self.state = "disconnected"
        self.transport.disconnect()

    def buildProtocol(self, addr):
        return self.factory.buildProtocol(addr)

    def connectionLost(self, reason=None):
        if not self.clientLost:
            self.clientLost = True
            self.factory.clientConnectionLost(self, reason)

    def connectionFailed(self, reason=None):
        if not self.clientFailed:
            self.clientFailed = True
            self.factory.clientConnectionFailed(self, reason)