summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql/PG_Stream.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/jdbc/postgresql/PG_Stream.java')
-rw-r--r--src/interfaces/jdbc/postgresql/PG_Stream.java58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/interfaces/jdbc/postgresql/PG_Stream.java b/src/interfaces/jdbc/postgresql/PG_Stream.java
index f786b507d1b..9002ccda7bd 100644
--- a/src/interfaces/jdbc/postgresql/PG_Stream.java
+++ b/src/interfaces/jdbc/postgresql/PG_Stream.java
@@ -20,7 +20,16 @@ public class PG_Stream
{
private Socket connection;
private InputStream pg_input;
- private OutputStream pg_output;
+ private BufferedOutputStream pg_output;
+
+ // This is the error message returned when an EOF occurs
+ private static final String EOF_MSG = "The backend has broken the connection. Possibly the action you have attempted has caused it to close.";
+
+ // This is the error message returned when an IOException occurs
+ private static final String IOE_MSG = "IOError while reading from backend: ";
+
+ // This is the error message returned when flushing the stream.
+ private static final String FLUSH_MSG = "Error flushing output: ";
/**
* Constructor: Connect to the PostgreSQL back end and return
@@ -33,8 +42,13 @@ public class PG_Stream
public PG_Stream(String host, int port) throws IOException
{
connection = new Socket(host, port);
+
+ // Submitted by Jason Venner <jason@idiom.com> adds a 10x speed
+ // improvement on FreeBSD machines (caused by a bug in their TCP Stack)
+ connection.setTcpNoDelay(true);
+
pg_input = connection.getInputStream();
- pg_output = connection.getOutputStream();
+ pg_output = new BufferedOutputStream(connection.getOutputStream());
}
/**
@@ -45,7 +59,6 @@ public class PG_Stream
*/
public void SendChar(int val) throws IOException
{
- //pg_output.write(val);
byte b[] = new byte[1];
b[0] = (byte)val;
pg_output.write(b);
@@ -165,9 +178,9 @@ public class PG_Stream
try
{
c = pg_input.read();
- if (c < 0) throw new IOException("EOF");
+ if (c < 0) throw new IOException(EOF_MSG);
} catch (IOException e) {
- throw new SQLException("Error reading from backend: " + e.toString());
+ throw new SQLException(IOE_MSG + e.toString());
}
return c;
}
@@ -190,11 +203,11 @@ public class PG_Stream
int b = pg_input.read();
if (b < 0)
- throw new IOException("EOF");
+ throw new IOException(EOF_MSG);
n = n | (b << (8 * i)) ;
}
} catch (IOException e) {
- throw new SQLException("Error reading from backend: " + e.toString());
+ throw new SQLException(IOE_MSG + e.toString());
}
return n;
}
@@ -217,11 +230,11 @@ public class PG_Stream
int b = pg_input.read();
if (b < 0)
- throw new IOException("EOF");
+ throw new IOException(EOF_MSG);
n = b | (n << 8);
}
} catch (IOException e) {
- throw new SQLException("Error reading from backend: " + e.toString());
+ throw new SQLException(IOE_MSG + e.toString());
}
return n;
}
@@ -246,7 +259,7 @@ public class PG_Stream
{
int c = pg_input.read();
if (c < 0)
- throw new IOException("EOF");
+ throw new IOException(EOF_MSG);
else if (c == 0)
break;
else
@@ -255,7 +268,7 @@ public class PG_Stream
if (s >= maxsiz)
throw new IOException("Too Much Data");
} catch (IOException e) {
- throw new SQLException("Error reading from backend: " + e.toString());
+ throw new SQLException(IOE_MSG + e.toString());
}
String v = new String(rst, 0, s);
return v;
@@ -314,21 +327,8 @@ public class PG_Stream
private byte[] Receive(int siz) throws SQLException
{
byte[] answer = new byte[siz];
- int s = 0;
-
- try
- {
- while (s < siz)
- {
- int w = pg_input.read(answer, s, siz - s);
- if (w < 0)
- throw new IOException("EOF");
- s += w;
- }
- } catch (IOException e) {
- throw new SQLException("Error reading from backend: " + e.toString());
- }
- return answer;
+ Receive(answer,0,siz);
+ return answer;
}
/**
@@ -349,11 +349,11 @@ public class PG_Stream
{
int w = pg_input.read(b, off+s, siz - s);
if (w < 0)
- throw new IOException("EOF");
+ throw new IOException(EOF_MSG);
s += w;
}
} catch (IOException e) {
- throw new SQLException("Error reading from backend: " + e.toString());
+ throw new SQLException(IOE_MSG + e.toString());
}
}
@@ -367,7 +367,7 @@ public class PG_Stream
try {
pg_output.flush();
} catch (IOException e) {
- throw new SQLException("Error flushing output: " + e.toString());
+ throw new SQLException(FLUSH_MSG + e.toString());
}
}