現在のC言語のアプリケーションGUIをdlangを使ってWeb GUIに置き換えようとしています。アプリケーションはOpenSuse 12.3 x32プラットフォーム上にまだ存在し、FIFOパイプを介してGUIと通信します。linuxのc-appとdlangの間でネームパイプを作成して構造体データを交換する
メッセージはCで作成され、プロジェクト内のすべての関係者がグローバルにアクセスできる単一の.hファイルで定義された構造体です。
私の問題では、パイプを作成してそれに書き込んだり、 "cat"というパイプでパイプの内容を読み込んだりすることができましたが、dlangでpipe-handleを使って読むと、パイプから-1が読み込まれたことを知っています。なぜ "?????"のアイデアすべては、私は以下の コードは、最初のサーバー
import std.range, std.stdio, std.conv;
import core.stdc.string;
import core.stdc.stdio;
import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import core.sys.posix.fcntl;
import core.sys.posix.sys.stat;
//extern (C) uint read(int, void *, uint);
extern (C) uint write(int, void *, ulong);
struct IOREQ {
short fc; /* function code */
short rs; /* return code */
short src; /* return in fifo-pipe */
};
int fd = -1;
int freader = -1;
char [1024] rbuf = "";
void main(string[] args) {
int st = mknod("/Users/anders/pipes/4321", S_IFIFO|octal!666,0);
close(st);
fd = open("/Users/anders/pipes/4321", O_WRONLY);
//freader = open("/Users/anders/pipes/4321", O_RDONLY);
char [1024]sbuf;
char [1024]rbuf;
int res = -1;
sbuf = "Testing a message in pure text to send to client using a FIFO-pipe\n";
while(1){
res = write(fd, cast(void *)sbuf, sbuf.sizeof);
writeln("Wrote data in the pipe, :", res);
sleep(2);
sbuf = "Testing another message in pure text to send to client\n";
}
close(fd);
}
我々はスウェーデンで言うような問題、SBSを発見した
import std.range, std.stdio, std.conv;
import core.stdc.string;
import core.stdc.stdio;
import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import core.sys.posix.fcntl;
import core.sys.posix.sys.stat;
import core.thread;
extern (C) uint read(int, void *, uint);
//extern (C) uint write(int, void *, ulong);
struct IOREQ {
...
};
int fd = -1;
int freader = -1;
char [1024] rbuf = "";
void main(string[] args) {
//int st = mknode("/Users/anders/pipes/4321", S_FIFO|0666,0);
freader = open("/Users/anders/pipes/4321", O_RDONLY);
//freader = open("/Users/anders/pipes/4321", O_RDONLY);
if(freader < 0)
{
writeln("Couldn't open pipe ", freader);
}
else
{
char [1024]sbuf;
char [1024]rbuf;
writeln("Reading data from pipeserver\n");
int st = read(fd, cast(void *)sbuf, sbuf.sizeof);
writeln("Done reading, read :", st);
writeln("Data :\n", sbuf);
close(freader);
}
}
'read'呼び出しが何かがうまくいかなかったことを意味する' -1'を返し、エラーがあることを確認する必要があります。 –
ああ、私が端末から "cat"パイプにwhileループが動作しようとすると、何度も何度もメッセージが出ます。 dlangコードは、最初の書き込み後にループから抜け出すだけです。 –
何らかのエラーがあることがわかりましたが(-1が返されました)、コードのどこに問題があるのかわかりません。 Interrestingは、猫がメッセージを表示していれば、パイプを拾うのを待ちます。 –