Changeset 10574


Ignore:
Timestamp:
Aug 27, 2008, 9:49:04 AM (11 years ago)
Author:
gb
Message:

More changes to ease Windows bootstrapping - error returns, socket fds
vs handles, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-sockets.lisp

    r10544 r10574  
    4848            SOCKET-ERROR-IDENTIFIER
    4949            SOCKET-ERROR-SITUATION
    50             WITH-OPEN-SOCKET)))
     50            WITH-OPEN-SOCKET))
     51  #+windows-target
     52  (defmacro check-winsock-error (form)
     53    (let* ((val (gensym)))
     54      `(let* ((,val ,form))
     55        (if (< ,val 0)
     56          (%get-winsock-error)
     57          ,val))))
     58  (defmacro check-socket-error (form)
     59    #+windows-target `(check-winsock-error ,form)
     60    #-windows-target `(int-errno-call ,form))
     61  )
     62
     63(declaim (inline socket-handle))
     64(defun socket-handle (fd)
     65  #+windows-target (#__get_osfhandle fd)
     66  #-windows-target fd)
     67
     68#+windows-target
     69(defun %get-winsock-error ()
     70  (- (#_WSAGetLastError)))
    5171
    5272;;; The PPC is big-endian (uses network byte order), which makes
     
    11961216
    11971217(defun c_socket_1 (domain type protocol)
    1198   (int-errno-call (#_socket domain type protocol)))
     1218  #-windows-target (int-errno-call (#_socket domain type protocol))
     1219  #+windows-target (let* ((handle (#_socket domain type protocol)))
     1220                     (if (< handle 0)
     1221                       (%get-winsock-error)
     1222                       (let* ((fd (#__open_osfhandle handle 0)))
     1223                         (if (< fd 0)
     1224                           (progn
     1225                             (#_CloseHandle handle)
     1226                             (%get-errno))
     1227                           fd)))))
     1228
     1229
    11991230
    12001231(defun c_socket (domain type protocol)
     
    12421273
    12431274(defun c_bind (sockfd sockaddr addrlen)
    1244   (int-errno-call (#_bind sockfd sockaddr addrlen)))
     1275  (check-socket-error (#_bind (socket-handle sockfd) sockaddr addrlen)))
    12451276
    12461277
     
    12541285         (progn
    12551286           (fd-set-flags sockfd (logior flags #$O_NONBLOCK))
    1256            (let* ((err (int-errno-call (#_connect sockfd addr len))))
     1287           (let* ((err (check-socket-error (#_connect (socket-handle sockfd) addr len))))
    12571288             (cond ((or (eql err (- #$EINPROGRESS)) (eql err (- #$EINTR)))
    12581289                    (if (process-output-wait sockfd timeout-in-milliseconds)
     
    12631294
    12641295(defun c_listen (sockfd backlog)
    1265   (int-errno-call (#_listen sockfd backlog)))
     1296  (check-socket-error (#_listen (socket-handle sockfd) backlog)))
    12661297
    12671298(defun c_accept (sockfd addrp addrlenp)
    12681299  (ignoring-eintr
    1269    (int-errno-call (#_accept sockfd addrp addrlenp))))
     1300   (check-socket-error (#_accept (socket-handle sockfd) addrp addrlenp))))
    12701301
    12711302(defun c_getsockname (sockfd addrp addrlenp)
    1272   (int-errno-call (#_getsockname sockfd addrp addrlenp)))
     1303  (check-socket-error (#_getsockname (socket-handle sockfd) addrp addrlenp)))
    12731304
    12741305(defun c_getpeername (sockfd addrp addrlenp)
    1275   (int-errno-call (#_getpeername sockfd addrp addrlenp)))
     1306  (check-socket-error (#_getpeername (socket-handle sockfd) addrp addrlenp)))
    12761307
    12771308(defun c_socketpair (domain type protocol socketsptr)
    1278   (int-errno-call (#_socketpair domain type protocol socketsptr)))
     1309  (check-socket-error (#_socketpair domain type protocol socketsptr)))
    12791310
    12801311
    12811312(defun c_sendto (sockfd msgptr len flags addrp addrlen)
    1282   (int-errno-call (#_sendto sockfd msgptr len flags addrp addrlen)))
     1313  (check-socket-error (#_sendto (socket-handle sockfd) msgptr len flags addrp addrlen)))
    12831314
    12841315(defun c_recvfrom (sockfd bufptr len flags addrp addrlenp)
    1285   (int-errno-call (#_recvfrom sockfd bufptr len flags addrp addrlenp)))
     1316  (check-socket-error (#_recvfrom (socket-handle sockfd) bufptr len flags addrp addrlenp)))
    12861317
    12871318(defun c_shutdown (sockfd how)
    1288   (int-errno-call (#_shutdown sockfd how)))
     1319  (check-socket-error (#_shutdown (socket-handle sockfd) how)))
    12891320
    12901321(defun c_setsockopt (sockfd level optname optvalp optlen)
    1291   (int-errno-call (#_setsockopt sockfd level optname optvalp optlen)))
     1322  (check-socket-error (#_setsockopt (socket-handle sockfd) level optname optvalp optlen)))
    12921323
    12931324(defun c_getsockopt (sockfd level optname optvalp optlenp)
    1294   (int-errno-call (#_getsockopt sockfd level optname optvalp optlenp)))
     1325  (check-socket-error (#_getsockopt (socket-handle sockfd) level optname optvalp optlenp)))
    12951326
    12961327(defun c_sendmsg (sockfd msghdrp flags)
    1297   (int-errno-call (#_sendmsg sockfd msghdrp flags)))
     1328  (check-socket-error (#_sendmsg (socket-handle sockfd) msghdrp flags)))
    12981329
    12991330(defun c_recvmsg (sockfd msghdrp flags)
    1300   (int-errno-call   (#_recvmsg sockfd msghdrp flags)))
     1331  (check-socket-error   (#_recvmsg (socket-handle sockfd) msghdrp flags)))
    13011332
    13021333
Note: See TracChangeset for help on using the changeset viewer.