Changeset 13894


Ignore:
Timestamp:
Jun 27, 2010, 2:51:39 AM (9 years ago)
Author:
svspire
Message:

Fix #'send-to and #'receive-from so they DTRT with string buffers.

File:
1 edited

Legend:

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

    r13382 r13894  
    955955
    956956(defmethod send-to ((socket udp-socket) msg size
    957                     &key remote-host remote-port offset)
     957                    &key remote-host remote-port offset (external-format :ISO-8859-1))
    958958  "Send a UDP packet over a socket."
    959959  (let ((fd (socket-device socket)))
     960    (when (stringp msg) (setf msg (ccl::ENCODE-STRING-TO-OCTETS msg :external-format external-format)))
    960961    (multiple-value-setq (msg offset) (verify-socket-buffer msg offset size))
    961962    (unless remote-host
     
    973974      (setf (pref sockaddr :sockaddr_in.sin_port)
    974975            (if remote-port (port-as-inet-port remote-port "udp") 0))
    975       (%stack-block ((bufptr size))
     976            (%stack-block ((bufptr size))
    976977        (%copy-ivector-to-ptr msg offset bufptr 0 size)
    977978        (socket-call socket "sendto"
     
    979980            (c_sendto fd bufptr size 0 sockaddr (record-length :sockaddr_in))))))))
    980981
    981 (defmethod receive-from ((socket udp-socket) size &key buffer extract offset)
     982(defmethod receive-from ((socket udp-socket) size &key buffer extract offset (encoding #.(lookup-character-encoding :iso-8859-1)))
    982983  "Read a UDP packet from a socket. If no packets are available, wait for
    983 a packet to arrive. Returns four values:
     984  a packet to arrive.
     985  Returns four values:
    984986  The buffer with the data
    985987  The number of bytes read
     
    10031005      (setf (pref namelen :signed) (record-length :sockaddr_in))
    10041006      (%stack-block ((bufptr size))
    1005         (setq ret-size (socket-call socket "recvfrom"
    1006                          (with-eagain fd :input
    1007                            (c_recvfrom fd bufptr size 0 sockaddr namelen))))
    1008         (unless vec
    1009           (setq vec (make-array ret-size
    1010                                 :element-type
    1011                                 (ecase (socket-format socket)
    1012                                   ((:text) 'base-char)
    1013                                   ((:binary :bivalent) '(unsigned-byte 8))))
    1014                 vec-offset 0))
    1015         (%copy-ptr-to-ivector bufptr 0 vec vec-offset ret-size))
     1007        (setq ret-size (socket-call socket "recvfrom"
     1008                                    (with-eagain fd :input
     1009                                      (c_recvfrom fd bufptr size 0 sockaddr namelen))))
     1010        (unless vec
     1011          (setq vec (make-array ret-size
     1012                                :element-type
     1013                                (ecase (socket-format socket)
     1014                                  ((:text) 'base-char)
     1015                                  ((:binary :bivalent) '(unsigned-byte 8))))
     1016                vec-offset 0))
     1017       
     1018        (ecase (socket-format socket)
     1019          ((:text) (funcall (character-encoding-memory-decode-function encoding) bufptr ret-size 0 vec))
     1020          ((:binary (%copy-ptr-to-ivector bufptr 0 vec vec-offset ret-size)))))
     1021     
    10161022      (values (cond ((null buffer)
    10171023                     vec)
Note: See TracChangeset for help on using the changeset viewer.