src/share/vm/utilities/ostream.cpp

changeset 2322
828eafbd85cc
parent 2314
f95d63e2154a
child 2515
d8a72fbc4be7
equal deleted inserted replaced
2314:f95d63e2154a 2322:828eafbd85cc
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "compiler/compileLog.hpp" 26 #include "compiler/compileLog.hpp"
27 #include "oops/oop.inline.hpp" 27 #include "oops/oop.inline.hpp"
28 #include "runtime/arguments.hpp" 28 #include "runtime/arguments.hpp"
29 #include "runtime/hpi.hpp"
30 #include "utilities/defaultStream.hpp" 29 #include "utilities/defaultStream.hpp"
31 #include "utilities/ostream.hpp" 30 #include "utilities/ostream.hpp"
32 #include "utilities/top.hpp" 31 #include "utilities/top.hpp"
33 #include "utilities/xmlstream.hpp" 32 #include "utilities/xmlstream.hpp"
34 #ifdef TARGET_OS_FAMILY_linux 33 #ifdef TARGET_OS_FAMILY_linux
35 # include "hpi_linux.hpp"
36 # include "os_linux.inline.hpp" 34 # include "os_linux.inline.hpp"
37 #endif 35 #endif
38 #ifdef TARGET_OS_FAMILY_solaris 36 #ifdef TARGET_OS_FAMILY_solaris
39 # include "hpi_solaris.hpp"
40 # include "os_solaris.inline.hpp" 37 # include "os_solaris.inline.hpp"
41 #endif 38 #endif
42 #ifdef TARGET_OS_FAMILY_windows 39 #ifdef TARGET_OS_FAMILY_windows
43 # include "hpi_windows.hpp"
44 # include "os_windows.inline.hpp" 40 # include "os_windows.inline.hpp"
45 #endif 41 #endif
46 42
47 extern "C" void jio_print(const char* s); // Declarationtion of jvm method 43 extern "C" void jio_print(const char* s); // Declarationtion of jvm method
48 44
877 // Network access 873 // Network access
878 networkStream::networkStream() : bufferedStream(1024*10, 1024*10) { 874 networkStream::networkStream() : bufferedStream(1024*10, 1024*10) {
879 875
880 _socket = -1; 876 _socket = -1;
881 877
882 hpi::initialize_socket_library(); 878 int result = os::socket(AF_INET, SOCK_STREAM, 0);
883
884 int result = hpi::socket(AF_INET, SOCK_STREAM, 0);
885 if (result <= 0) { 879 if (result <= 0) {
886 assert(false, "Socket could not be created!"); 880 assert(false, "Socket could not be created!");
887 } else { 881 } else {
888 _socket = result; 882 _socket = result;
889 } 883 }
890 } 884 }
891 885
892 int networkStream::read(char *buf, size_t len) { 886 int networkStream::read(char *buf, size_t len) {
893 return hpi::recv(_socket, buf, (int)len, 0); 887 return os::recv(_socket, buf, (int)len, 0);
894 } 888 }
895 889
896 void networkStream::flush() { 890 void networkStream::flush() {
897 if (size() != 0) { 891 if (size() != 0) {
898 int result = hpi::raw_send(_socket, (char *)base(), (int)size(), 0); 892 int result = os::raw_send(_socket, (char *)base(), (int)size(), 0);
899 assert(result != -1, "connection error"); 893 assert(result != -1, "connection error");
900 assert(result == (int)size(), "didn't send enough data"); 894 assert(result == (int)size(), "didn't send enough data");
901 } 895 }
902 reset(); 896 reset();
903 } 897 }
907 } 901 }
908 902
909 void networkStream::close() { 903 void networkStream::close() {
910 if (_socket != -1) { 904 if (_socket != -1) {
911 flush(); 905 flush();
912 hpi::socket_close(_socket); 906 os::socket_close(_socket);
913 _socket = -1; 907 _socket = -1;
914 } 908 }
915 } 909 }
916 910
917 bool networkStream::connect(const char *ip, short port) { 911 bool networkStream::connect(const char *ip, short port) {
920 server.sin_family = AF_INET; 914 server.sin_family = AF_INET;
921 server.sin_port = htons(port); 915 server.sin_port = htons(port);
922 916
923 server.sin_addr.s_addr = inet_addr(ip); 917 server.sin_addr.s_addr = inet_addr(ip);
924 if (server.sin_addr.s_addr == (uint32_t)-1) { 918 if (server.sin_addr.s_addr == (uint32_t)-1) {
925 #ifdef _WINDOWS 919 struct hostent* host = os::get_host_by_name((char*)ip);
926 struct hostent* host = hpi::get_host_by_name((char*)ip);
927 #else
928 struct hostent* host = gethostbyname(ip);
929 #endif
930 if (host != NULL) { 920 if (host != NULL) {
931 memcpy(&server.sin_addr, host->h_addr_list[0], host->h_length); 921 memcpy(&server.sin_addr, host->h_addr_list[0], host->h_length);
932 } else { 922 } else {
933 return false; 923 return false;
934 } 924 }
935 } 925 }
936 926
937 927
938 int result = hpi::connect(_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_in)); 928 int result = os::connect(_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_in));
939 return (result >= 0); 929 return (result >= 0);
940 } 930 }
941 931
942 #endif 932 #endif

mercurial