Skip to content

Commit 0092322

Browse files
author
Dave Cramer
committed
Part of Anders Bengtsson's patch to clean up Connection.java
1 parent d96c29a commit 0092322

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.postgresql.core;
2+
3+
import org.postgresql.PG_Stream;
4+
import java.io.IOException;
5+
6+
/**
7+
* Sent to the backend to initialize a newly created connection.
8+
*
9+
* $Id: StartupPacket.java,v 1.1 2002/03/21 02:40:03 davec Exp $
10+
*/
11+
12+
public class StartupPacket
13+
{
14+
private static final int SM_DATABASE = 64;
15+
private static final int SM_USER = 32;
16+
private static final int SM_OPTIONS = 64;
17+
private static final int SM_UNUSED = 64;
18+
private static final int SM_TTY = 64;
19+
20+
private int protocolMajor;
21+
private int protocolMinor;
22+
private String user;
23+
private String database;
24+
25+
public StartupPacket(int protocolMajor, int protocolMinor, String user, String database) {
26+
this.protocolMajor = protocolMajor;
27+
this.protocolMinor = protocolMinor;
28+
this.user = user;
29+
this.database = database;
30+
}
31+
32+
public void writeTo(PG_Stream stream) throws IOException
33+
{
34+
stream.SendInteger(4 + 4 + SM_DATABASE + SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY, 4);
35+
stream.SendInteger(protocolMajor, 2);
36+
stream.SendInteger(protocolMinor, 2);
37+
stream.Send(database.getBytes(), SM_DATABASE);
38+
39+
// This last send includes the unused fields
40+
stream.Send(user.getBytes(), SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY);
41+
}
42+
}
43+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy