Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It reads no more than 8192 bytes #31

Open
asocjal opened this issue May 25, 2018 · 1 comment
Open

It reads no more than 8192 bytes #31

asocjal opened this issue May 25, 2018 · 1 comment

Comments

@asocjal
Copy link

asocjal commented May 25, 2018

For small amount of data, everything is fine. For more than 8192 bytes it reads only first 8192 bytes. DSo 'BYTES READED' is never more than 8192. Desn't matter what is bufferSize value:

`

public String exec(String channelId, String requestJson) throws RpcException {
	try {
		Require.notNull(channelId, "channelId");
		Require.notNull(requestJson, "requestJson");
		
		String respStr = null;

		UnixDomainSocketClient socket = channels.get(channelId);
		if (socket == null) {
			socket = new UnixDomainSocketClient(socketFilePath, JUDS.SOCK_STREAM);
			channels.put(channelId, socket);
		}

		InputStream in = socket.getInputStream();
		OutputStream out = socket.getOutputStream();
		
		try {
			PrintWriter w = new PrintWriter(out);
			w.print(requestJson);
			w.flush();
		} catch (Throwable ex) {
			throw new Exception("Cannot send request \"" + requestJson + "\" to c-lightning RPC socket", ex);
		}

		try {
			InputStreamReader r = new InputStreamReader(in);

			CharBuffer respChBuf = CharBuffer.allocate(bufferSize);
			
			StringBuilder resp = new StringBuilder();
			int bytesRead;
			do {
				bytesRead = r.read(respChBuf);
				LOGGER.debug("Readed bytes: " + bytesRead);
				if(bytesRead > 0) {
					respChBuf.flip();
					resp.append(respChBuf.toString());
				}
			} while(bytesRead == bufferSize);
			respStr = resp.toString();
			LOGGER.info("BYTES READED: " + resp.length());
		} catch (Throwable ex) {
			throw new Exception("Cannot get response from c-lightning RPC socket", ex);
		}
		return Require.notNull(respStr, "respStr");
	} catch (Throwable ex) {
		throw new RpcException("Cannot execute request '" + requestJson + "'", ex);
	}
}`
@zenloo
Copy link

zenloo commented Feb 23, 2021

Hey, is this an issue of JUDS or CharBUffer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants