Skip to content

Commit 994a4db

Browse files
committed
Force TCP v4 for socket to Java server. Fixes tesseract-ocr#3000
Without any hints, we can end up with a UDP socket which won't work with the TCP socket that the Java display server is listening on. Use hints for TCP v4 so that we get the right kind of socket returned. Also, delete some obsolete comments nearby.
1 parent 5530cb7 commit 994a4db

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/viewer/svutil.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,10 @@ static const char *ScrollViewProg() {
244244

245245
// The arguments to the program to invoke to start ScrollView
246246
static std::string ScrollViewCommand(const std::string &scrollview_path) {
247-
// The following ugly ifdef is to enable the output of the java runtime
248-
// to be sent down a black hole on non-windows to ignore all the
249-
// exceptions in piccolo. Ideally piccolo would be debugged to make
250-
// this unnecessary.
251-
// Also the path has to be separated by ; on windows and : otherwise.
247+
// Quote our paths on Windows to deal with spaces
252248
# ifdef _WIN32
253249
const char cmd_template[] =
254250
"-Djava.library.path=\"%s\" -jar \"%s/ScrollView.jar\"";
255-
256251
# else
257252
const char cmd_template[] =
258253
"-c \"trap 'kill %%1' 0 1 2 ; java "
@@ -279,6 +274,7 @@ SVNetwork::SVNetwork(const char *hostname, int port) {
279274
buffer_ptr_ = nullptr;
280275

281276
struct addrinfo *addr_info = nullptr;
277+
struct addrinfo hints = {0, PF_INET, SOCK_STREAM};
282278
auto port_string = std::to_string(port);
283279
# ifdef _WIN32
284280
// Initialize Winsock
@@ -289,7 +285,7 @@ SVNetwork::SVNetwork(const char *hostname, int port) {
289285
}
290286
# endif // _WIN32
291287

292-
if (getaddrinfo(hostname, port_string.c_str(), nullptr, &addr_info) != 0) {
288+
if (getaddrinfo(hostname, port_string.c_str(), &hints, &addr_info) != 0) {
293289
std::cerr << "Error resolving name for ScrollView host "
294290
<< std::string(hostname) << ":" << port << std::endl;
295291
# ifdef _WIN32

0 commit comments

Comments
 (0)