diff options
-rw-r--r-- | doc/examples/socket.h | 12 | ||||
-rw-r--r-- | doc/examples/tls_client.cpp | 5 | ||||
-rw-r--r-- | doc/examples/tls_server.cpp | 4 |
3 files changed, 12 insertions, 9 deletions
diff --git a/doc/examples/socket.h b/doc/examples/socket.h index 6d28afacf..f7ce98fea 100644 --- a/doc/examples/socket.h +++ b/doc/examples/socket.h @@ -24,6 +24,7 @@ typedef SOCKET socket_t; const socket_t invalid_socket = INVALID_SOCKET; #define socket_error_code WSAGetLastError() + typedef int ssize_t; class SocketInitializer { @@ -51,6 +52,7 @@ typedef int socket_t; const socket_t invalid_socket = -1; #define socket_error_code errno + #define closesocket close class SocketInitializer {}; #endif @@ -73,7 +75,7 @@ class Socket { if(sockfd != invalid_socket) { - if(::close(sockfd) != 0) + if(::closesocket(sockfd) != 0) throw std::runtime_error("Socket::close failed"); sockfd = invalid_socket; } @@ -109,7 +111,7 @@ class Server_Socket { if(sockfd != invalid_socket) { - if(::close(sockfd) != 0) + if(::closesocket(sockfd) != 0) throw std::runtime_error("Server_Socket::close failed"); sockfd = invalid_socket; } @@ -152,7 +154,7 @@ Socket::Socket(const std::string& host, unsigned short port) : peer(host) if(::connect(fd, (sockaddr*)&socket_info, sizeof(struct sockaddr)) != 0) { - ::close(fd); + ::closesocket(fd); throw std::runtime_error("Socket: connect failed"); } @@ -239,13 +241,13 @@ Server_Socket::Server_Socket(unsigned short port) if(::bind(fd, (sockaddr*)&socket_info, sizeof(struct sockaddr)) != 0) { - ::close(fd); + ::closesocket(fd); throw std::runtime_error("Server_Socket: bind failed"); } if(::listen(fd, 100) != 0) // FIXME: totally arbitrary { - ::close(fd); + ::closesocket(fd); throw std::runtime_error("Server_Socket: listen failed"); } diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp index 4896a28f8..cedfe1ca8 100644 --- a/doc/examples/tls_client.cpp +++ b/doc/examples/tls_client.cpp @@ -63,7 +63,8 @@ int main(int argc, char* argv[]) std::string http_command = "GET / HTTP/1.0\r\n\r\n"; #endif - tls.write((const byte*)http_command.c_str(), http_command.length()); + tls.write((const Botan::byte*)http_command.c_str(), + http_command.length()); size_t total_got = 0; @@ -72,7 +73,7 @@ int main(int argc, char* argv[]) if(tls.is_closed()) break; - byte buf[128+1] = { 0 }; + Botan::byte buf[128+1] = { 0 }; size_t got = tls.read(buf, sizeof(buf)-1); printf("%s", buf); fflush(0); diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp index 0c68ead3d..153b26d04 100644 --- a/doc/examples/tls_server.cpp +++ b/doc/examples/tls_server.cpp @@ -82,12 +82,12 @@ int main(int argc, char* argv[]) printf("Writing some text\n"); char msg[] = "Foo\nBar\nBaz\nQuux\n"; - tls.write((const byte*)msg, strlen(msg)); + tls.write((const Botan::byte*)msg, strlen(msg)); printf("Now trying a read...\n"); char buf[1024] = { 0 }; - u32bit got = tls.read((byte*)buf, sizeof(buf)-1); + u32bit got = tls.read((Botan::byte*)buf, sizeof(buf)-1); printf("%d: '%s'\n", got, buf); tls.close(); |