| 133 | } |
| 134 | |
| 135 | func (ss *stdioServer) Start() error { |
| 136 | log.Info().Msg("Starting stdio mode - reading JSON requests from stdin") |
| 137 | |
| 138 | scanner := bufio.NewScanner(ss.stdin) |
| 139 | |
| 140 | const maxCapacity = 512 * 1024 // 512KB |
| 141 | buf := make([]byte, maxCapacity) |
| 142 | scanner.Buffer(buf, maxCapacity) |
| 143 | |
| 144 | for scanner.Scan() { |
| 145 | line := scanner.Bytes() |
| 146 | if len(line) == 0 { |
| 147 | continue // Skip empty lines |
| 148 | } |
| 149 | ss.handleRequest(line) |
| 150 | } |
| 151 | |
| 152 | // Scanner stopped, check why |
| 153 | if err := scanner.Err(); err != nil { |
| 154 | log.Error().Err(err).Msg("Error reading from stdin") |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | log.Info().Msg("EOF reached on stdin, shutting down") |
| 159 | return nil |
| 160 | } |
| 161 | |
| 162 | func (ss *stdioServer) handleRequest(requestBytes []byte) { |
| 163 | var req jsonRpcRequest |