Synchronized files from gborg repository
[mono.git] / mcs / class / Npgsql / Npgsql / NpgsqlBackEndKeyData.cs
1 // created on 11/6/2002 at 11:53
2
3 // Npgsql.NpgsqlBackEndKeyData.cs
4 // 
5 // Author:
6 //      Francisco Jr. (fxjrlists@yahoo.com.br)
7 //
8 //      Copyright (C) 2002 The Npgsql Development Team
9 //      npgsql-general@gborg.postgresql.org
10 //      http://gborg.postgresql.org/project/npgsql/projdisplay.php
11 //
12
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
17 // 
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 // Lesser General Public License for more details.
22 // 
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27
28 using System;
29 using System.IO;
30 using System.Text;
31 using System.Net;
32
33 namespace Npgsql
34 {
35         /// <summary>
36         /// This class represents a BackEndKeyData message received
37         /// from PostgreSQL
38         /// </summary>
39         internal sealed class NpgsqlBackEndKeyData
40         {
41                 // Logging related values
42     private static readonly String CLASSNAME = "NpgsqlBackEndKeyData";
43                 
44                 private Int32 process_id;
45                 private Int32 secret_key;
46                 
47                                 
48                 public void ReadFromStream(Stream input_stream)
49                 {
50                         NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".ReadFromStream()", LogLevel.Debug);
51                         
52                         Byte[] input_buffer = new Byte[8];
53                         
54                         // Read the BackendKeyData message contents. Two Int32 integers = 8 Bytes.
55                         input_stream.Read(input_buffer, 0, 8);
56                         process_id = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(input_buffer, 0));
57                         secret_key = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(input_buffer, 4));
58                         
59                 }
60                 
61                 public Int32 ProcessID
62                 {
63                         get
64                         {
65                                 NpgsqlEventLog.LogMsg("Got ProcessID. Value: " + process_id, LogLevel.Debug);
66                                 return process_id;
67                         }
68                 }
69                 
70                 public Int32 SecretKey
71                 {
72                         get
73                         {
74                                 NpgsqlEventLog.LogMsg("Got SecretKey. Value: " + secret_key, LogLevel.Debug);
75                                 return secret_key;
76                         }
77                 }
78         }
79 }