Skip to content

Commit

Permalink
[remote] Fix windows pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
artemm-bochkarev committed Jan 8, 2025
1 parent 8b000f7 commit e0d1213
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion java/com/jetbrains/cef/remote/NativeServerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static List<String> findRoots() {
for (File pipe: pipes) {
RpcExecutor exec = new RpcExecutor();
try {
exec.openPipeTransport(new ThriftTransport(pipe.getAbsolutePath()));
exec.openPipeTransport(new ThriftTransport(pipe));
String newRoot = exec.execObj(s -> s.getServerInfo("root"));
existingRoots.add(newRoot);
CefLog.Info("Found cef_server instance root_cache_path '%s' (pipe=%s).", newRoot, pipe.getName());
Expand Down
14 changes: 12 additions & 2 deletions java/com/jetbrains/cef/remote/ThriftTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class ThriftTransport {
ourDefaultClient = isTcpUsed() ? new ThriftTransport(getJavaHandlersPort()) : new ThriftTransport(getJavaHandlersPipe());
}

public ThriftTransport(File pipe) {
this.myPipe = OS.isWindows() ? pipe.getName() : pipe.getAbsolutePath() ;
this.myPort = 0;
}

public ThriftTransport(String pipe) {
this.myPipe = pipe;
this.myPort = 0;
Expand Down Expand Up @@ -227,8 +232,13 @@ public void close() {

public static File[] findPipes() {
if (OS.isWindows()) {
CefLog.Error("TODO: implement findPipes via Win32");
return null;
String[] pipes = WindowsPipe.findPipes(PIPENAME_CEF_SERVER + "*");
if (pipes == null || pipes.length == 0)
return null;
File[] result = new File[pipes.length];
for (int i = 0; i < pipes.length; i++)
result[i] = new File(pipes[i]);
return result;
}

return PIPE_DIR.toFile().listFiles((dir, name) -> name.startsWith(PIPENAME_CEF_SERVER));
Expand Down
3 changes: 3 additions & 0 deletions java/com/jetbrains/cef/remote/WindowsPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class WindowsPipe {
static String normalizePipePath(String path) {
return path.startsWith(WIN32_PIPE_PREFIX) ? path : WIN32_PIPE_PREFIX + path;
}

static native String[] findPipes(String fileName);

static native long CreateNamedPipe(
String lpName,
int dwOpenMode,
Expand Down
32 changes: 32 additions & 0 deletions remote/windows/WindowsPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <winerror.h>
#include <winnt.h>
#include <vector>
#include <string>

#define THROW_IO(prefix, ...) \
do { \
Expand Down Expand Up @@ -286,6 +287,37 @@ Java_com_jetbrains_cef_remote_WindowsPipe_PIPE_1ACCESS_1DUPLEX(
return PIPE_ACCESS_DUPLEX;
}

JNIEXPORT jobjectArray JNICALL
Java_com_jetbrains_cef_remote_WindowsPipe_findPipes(JNIEnv *env, jclass clazz, jstring jFileName) {
std::string fileName = "*";
const char* strFileName = env->GetStringUTFChars(jFileName, nullptr);
if (strFileName)
fileName.assign(strFileName);
env->ReleaseStringUTFChars(jFileName, strFileName);

WIN32_FIND_DATA data;
std::string lpFileName = "\\\\.\\pipe\\" + fileName;
HANDLE hFind = FindFirstFile(lpFileName.c_str(), &data);

if (hFind == INVALID_HANDLE_VALUE)
return nullptr;

std::vector<std::string> pipes;
do {
pipes.push_back(std::string(data.cFileName));
} while (FindNextFile(hFind, &data));
FindClose(hFind);

jobjectArray ret = (jobjectArray)env->NewObjectArray(pipes.size(),
env->FindClass("java/lang/String"),
env->NewStringUTF(""));
int c = 0;
for(auto& pipe: pipes)
env->SetObjectArrayElement(ret,c++,env->NewStringUTF(pipe.c_str()));

return ret;
}

#ifdef __cplusplus
}
#endif

0 comments on commit e0d1213

Please sign in to comment.