5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
21 #include "silcincludes.h"
23 /* Writes data from encrypted buffer to the socket connection. If the
24 data cannot be written at once, it will be written later with a timeout.
25 The data is written from the data section of the buffer, not from head
26 or tail section. This automatically pulls the data section towards end
27 after writing the data. */
29 int silc_socket_write(SilcSocketConnection sock)
34 /* Reads data from the socket connection into the incoming data buffer.
35 It reads as much as possible from the socket connection. This returns
36 amount of bytes read or -1 on error or -2 on case where all of the
37 data could not be read at once. */
39 int silc_socket_read(SilcSocketConnection sock)
44 /* Returns human readable socket error message. These are copied from the
49 if (strlen(s) > err_len)
51 memset(error, 0, error_len);
52 memcpy(error, s, strlen(s));
56 bool silc_socket_get_error(SilcSocketConnection sock, char *error,
59 if (sock->sock_error == KErrNone)
62 switch (sock->sock_error) {
64 PUT_ERROR("Item not found. (NotFound)");
66 PUT_ERROR("Uncategorized error. (General)");
68 PUT_ERROR("Operation cancelled. (Cancel)");
70 PUT_ERROR("A memory allocation failed. (NoMemory)");
71 case KErrNotSupported:
72 PUT_ERROR("A function is not supported in a given context. "
75 PUT_ERROR("An argument is out of range. (Argument)");
77 PUT_ERROR("Bad handle. (BadHandle)");
79 PUT_ERROR("Overflow. (Overflow)");
81 PUT_ERROR("Underflow. (Underflow)");
82 case KErrAlreadyExists:
83 PUT_ERROR("The resource already exists. (AlreadyExists)");
84 case KErrPathNotFound:
85 PUT_ERROR("In the context of file operations, the path was "
86 "not found. (PathNotFound)");
88 PUT_ERROR("A handle refers to a thread which has died (Died)");
90 PUT_ERROR("A requested resource is already in use. (InUse)");
91 case KErrServerTerminated:
92 PUT_ERROR("A client/server operation cannot execute, because the "
93 "server has terminated. (ServerTerminated)");
95 PUT_ERROR("A client/server operation cannot execute, because the server "
96 "is busy. (ServerBusy)");
98 PUT_ERROR("Resource not ready. Not initialized, or has no power. "
101 PUT_ERROR("A device is of unknown type. (Unknown)");
103 PUT_ERROR("Corrupted. (Corrupt)");
104 case KErrAccessDenied:
105 PUT_ERROR("Access denied. (AccessDenied)");
107 PUT_ERROR("The operation cannot be performed, because the resource "
108 "is locked. (Locked)");
110 PUT_ERROR("During a file write operation, not all the data could "
111 "be written. (Write)");
113 PUT_ERROR("A volume which was to be used for a file system operation "
114 "has been dismounted. (DisMounted)");
116 PUT_ERROR("End of file has been reached. (Eof)");
118 PUT_ERROR("A write operation could not complete, because the disk "
119 "was full. (DiskFull)");
121 PUT_ERROR("A driver DLL was of the wrong type. (BadDriver)");
123 PUT_ERROR("Name did not conform with the required syntax. (BadName)");
124 case KErrCommsLineFail:
125 PUT_ERROR("The communication line failed. (CommsLineFail)");
127 PUT_ERROR("A frame error occurred in a communications operation. "
129 case KErrCommsOverrun:
130 PUT_ERROR("An overrun was detected by a communications driver. "
132 case KErrCommsParity:
133 PUT_ERROR("A parity error occurred in communications. (CommsParity)");
135 PUT_ERROR("An operation timed out. (TimedOut)");
136 case KErrCouldNotConnect:
137 PUT_ERROR("A session could not connect. (CouldNotConnect)");
138 case KErrCouldNotDisconnect:
139 PUT_ERROR("A session could not disconnect. (CouldNotDisconnect)");
140 case KErrDisconnected:
141 PUT_ERROR("The required session was disconnected. (Disconnected)");
142 case KErrBadLibraryEntryPoint:
143 PUT_ERROR("A library entry point was not of the required type. "
144 "(BadLibraryEntryPoint)");
145 case KErrBadDescriptor:
146 PUT_ERROR("A non-descriptor parameter was passed. (BadDescriptor)");
148 PUT_ERROR("An operation was aborted (Abort)");
150 PUT_ERROR("A number was too big (TooBig)");
151 case KErrDivideByZero:
152 PUT_ERROR("A divide-by-zero operation was attempted. (DivideByZero)");
154 PUT_ERROR("Insufficient power was available to complete an operation. "
157 PUT_ERROR("Network error: Resource temporarily unavailable (WouldBlock)");
159 PUT_ERROR("Network unreachable. (NetUnreach)");
160 case KErrHostUnreach:
161 PUT_ERROR("Host unreachable. (HostUnreach)");
162 case KErrNoProtocolOpt:
163 PUT_ERROR("No such protocol option. (NoProtocolOpt)");
165 PUT_ERROR("Urgent data arrived. (UrgentData)");
167 PUT_ERROR("Got NULL sokcet.");