This class mananges the physical connection to the SQL Server and
serialises its use amongst a number of virtual sockets.
This allows one physical connection to service a number of concurrent
statements.
Constraints and assumptions:
Callers will not attempt to read from the server without issuing a request first.
The end of a server reply can be identified as byte 2 of the header is non zero.
Comments:
This code will discard unread server data if a new request is issued.
Currently the higher levels of the driver attempt to do this but may be
we can just rely on this code instead.
A cancel can be issued by a caller only if the server is currently sending
data for the caller otherwise the cancel is ignored.
Cancel packets on their own are returned as extra records appended to the
previous packet so that the TdsCore module can process them.
This version of the class will start to cache results to disk once a predetermined
maximum buffer memory threshold has been passed. Small result sets that will fit
within a specified limit (default 8 packets) will continue to be held in memory
(even if the memory threshold has been passed) in the interests of efficiency.
author: Mike Hutchinson. version: $Id: SharedSocket.java,v 1.39 2007/07/08 21:38:13 bheineman Exp $
Construct a SharedSocket object specifying host name and
port.
Parameters: connection - the connection object throws: IOException - if socket open fails
Enable TLS encryption by creating a TLS socket over the
existing TCP/IP network socket.
Parameters: ssl - the SSL URL property value throws: IOException - if an I/O error occurs
Get a network packet. This may be read from the network directly or from
previously cached buffers.
Parameters: streamId - the originating ResponseStream object Parameters: buffer - the data buffer to receive the object (may be replaced) the data in a byte[] buffer throws: IOException - if an I/O error occurs
Convert two bytes (in network byte order) in a byte array into a Java
short integer.
Parameters: buf - array of data the 16 bit unsigned value as an int
Obtain an instance of a server request stream for this socket.
Parameters: bufferSize - the initial buffer size to be used by theRequestStream Parameters: maxPrecision - the maximum precision for numeric/decimal types the server request stream as a RequestStream
Obtain an instance of a server response stream for this socket.
NB. getRequestStream() must be used first to obtain the RequestStream
needed as a parameter for this method.
Parameters: requestStream - an existing server request stream object obtainedfrom this SharedSocket Parameters: bufferSize - the initial buffer size to be used by theRequestStream the server response stream as a ResponseStream
Send a network packet. If output for another virtual socket is
in progress this packet will be sent later.
Parameters: streamId - the originating RequestStream object Parameters: buffer - the data to send the same buffer received if emptied or another buffer w/ thesame size if the incoming buffer is cached (to avoid copying) throws: IOException - if an I/O error occurs