{"action":"created","issue":{"url":"https://api.github.com/repos/jflex-de/jflex/issues/131","labels_url":"https://api.github.com/repos/jflex-de/jflex/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/jflex-de/jflex/issues/131/comments","events_url":"https://api.github.com/repos/jflex-de/jflex/issues/131/events","html_url":"https://github.com/jflex-de/jflex/issues/131","id":57721165,"number":131,"title":"[Bug] Re-enable scanning interactively or from a network byte stream [sf#130]","user":{"login":"lsf37","id":5506585,"avatar_url":"https://avatars.githubusercontent.com/u/5506585?v=3","gravatar_id":"","url":"https://api.github.com/users/lsf37","html_url":"https://github.com/lsf37","followers_url":"https://api.github.com/users/lsf37/followers","following_url":"https://api.github.com/users/lsf37/following{/other_user}","gists_url":"https://api.github.com/users/lsf37/gists{/gist_id}","starred_url":"https://api.github.com/users/lsf37/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsf37/subscriptions","organizations_url":"https://api.github.com/users/lsf37/orgs","repos_url":"https://api.github.com/users/lsf37/repos","events_url":"https://api.github.com/users/lsf37/events{/privacy}","received_events_url":"https://api.github.com/users/lsf37/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jflex-de/jflex/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":20,"created_at":"2015-02-15T07:11:33Z","updated_at":"2015-02-15T22:18:14Z","closed_at":null,"body":"**Reported by jeningar on 2014-08-05 13:14 UTC**\nHi,\r\n\r\nWe have an application that receives commands over a TCP/IP socket. After each command a reply is sent. Normally the communication is interactive, which means a strict order of questions and answers. This works perfectly with jflex 1.4.x. (The grammar is easy from the jflex point of view. Every command is terminated by a semicolon, no read ahead necessary; this follows your FAQ answer on \"I want my scanner to read from a network byte stream or from interactive stdin. Can I do this with JFlex?\").\r\n\r\nNow we have some problems with Jflex 1.6.0.\r\n \r\nJflex generates following code in zzRefill():\r\n\r\n~~~~~\r\n...\r\n    int requested = zzBuffer.length - zzEndRead;\r\n    int totalRead = 0;\r\n    while (totalRead < requested) {\r\n      int numRead = zzReader.read(zzBuffer, zzEndRead + totalRead, requested - totalRead);\r\n      if (numRead == -1) {\r\n        break;\r\n      }\r\n      totalRead += numRead;\r\n    }\r\n...\r\n~~~~~\r\n\r\nThis code reads bytes from the input as long as the buffer isn't full or until EOF is reached. This is nice in case of reading a file, but leads to deadlocks if using an interactive scanner.\r\n\r\nThe easiest way to avoid the deadlock is to eliminate the while loop. If the assumption that a read() returns at least one character (or EOF) isn't valid, the while loop must be executed as long as nothing is read. (I tested this; it seems to work flawlessly).\r\n\r\nSince I assume there was a good reason for this piece of code, I'd like to have a command line option to eliminate the while loop here.\r\nI'd be delighted if someone would explain me why a repeated call of zzRefill() is worse than the while loop. It can't really be a performance issue. The costs of an I/O exceed by far the costs of a function call and a bit of basic arithmetic.\r\n\r\nRegards,\r\n\r\nRonald "},"comment":{"url":"https://api.github.com/repos/jflex-de/jflex/issues/comments/74440383","html_url":"https://github.com/jflex-de/jflex/issues/131#issuecomment-74440383","issue_url":"https://api.github.com/repos/jflex-de/jflex/issues/131","id":74440383,"user":{"login":"lsf37","id":5506585,"avatar_url":"https://avatars.githubusercontent.com/u/5506585?v=3","gravatar_id":"","url":"https://api.github.com/users/lsf37","html_url":"https://github.com/lsf37","followers_url":"https://api.github.com/users/lsf37/followers","following_url":"https://api.github.com/users/lsf37/following{/other_user}","gists_url":"https://api.github.com/users/lsf37/gists{/gist_id}","starred_url":"https://api.github.com/users/lsf37/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsf37/subscriptions","organizations_url":"https://api.github.com/users/lsf37/orgs","repos_url":"https://api.github.com/users/lsf37/repos","events_url":"https://api.github.com/users/lsf37/events{/privacy}","received_events_url":"https://api.github.com/users/lsf37/received_events","type":"User","site_admin":false},"created_at":"2015-02-15T22:18:14Z","updated_at":"2015-02-15T22:18:14Z","body":"Yes, looks like this needs to be revisited. Leaving the issue open. "}}