|
| 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