Re: Server is not active?

2013-09-28 Thread wagtail

On Saturday, 28 September 2013 at 05:28:05 UTC, ollie wrote:

On Fri, 27 Sep 2013 03:22:32 +0200, wagtail wrote:


A part of code shown below.

/++ Server main()
/
 ushort port = 9876;

auto inet = new InternetAddress(0.0.0.0,port);
Socket server = new TcpSocket(inet.addressFamily());

bool flag = true;

server.bind(inet);
server.listen(255);


Is there any particular reason to use 0.0.0.0 creating your
InternetAddress?  I think it should be the ip of your server
or just send port and ADDR_ANY will be used.

From Wikipedia:

In the Internet Protocol version 4 the address 0.0.0.0 is a 
non-routable
meta-address used to designate an invalid, unknown or non 
applicable

target.


Thank you for your reply!
I thought ADDR_ANY is the same as 0.0.0.0,so I used it.
This Server doesn't know ip of opponent client.
I tried rewriting code with using ADDR_ANY, but do not work...



curl_easy_setopt not callable

2013-09-28 Thread useo6

Hi guys,

I recently updated my DMD-setup to 2.063.2 and having some 
problems using the curl library. I wrote something like that:


curl_slist* headers;
headers = curl_slist_append(headers, cast(char*) toStringz(user ~ 
:  ~ pass));


curl_easy_setopt(ch, CurlOption.timeout_ms, timeout);
curl_easy_setopt(ch, CurlOption.httpheader, headers);

But dmd says that curl_easy_setopt ...is not callable using 
argument types (void, CurlOption, curl_slist*) and ... is not 
callable using argument types (void, CurlOption, ushort) 
(because timeout is ushort data type). Any suggestions how to 
solve these problems? In previous dmd-builds it compiles without 
any errors...


curl linux

2013-09-28 Thread Alexandr Druzhinin
I use curl in my application. If I link it with -lcurl - symbols are 
undefined (libcurl3 installed), if I link with -lphobos2 - it links. So 
curl is linked with libphobos2.so? But what to do if I need static 
linking? (ubuntu 12.04 x86_64, dmd 2.063.2)


Throwable catching

2013-09-28 Thread Alexandr Druzhinin
catching Throwable is wrong. But is it wrong if I used it in separate 
thread to prevent thread dying like:


static void run()
{
while(true)
{
try
{
/// do work
...

// interacting with parent
auto msg = receiveTimeout(dur!msecs(1),
(string command)
{
/// process command from parent
if(some_condition_is_true)
break; // finish
   // execution
}
);
}
catch(Throwable t)
{
/// some diagnostic message
}
}
}

...

auto child = spawn(run);

...

?


Re: Throwable catching

2013-09-28 Thread Jonathan M Davis
On Saturday, September 28, 2013 15:42:43 Alexandr Druzhinin wrote:
 catching Throwable is wrong. But is it wrong if I used it in separate
 thread to prevent thread dying like:
 
 static void run()
 {
   while(true)
   {
   try
   {
   /// do work
   ...
 
   // interacting with parent
   auto msg = receiveTimeout(dur!msecs(1),
   (string command)
   {
   /// process command from parent
   if(some_condition_is_true)
   break; // finish
  // execution
   }
   );
   }
   catch(Throwable t)
   {
   /// some diagnostic message
   }
   }
 }
 
 ...
 
 auto child = spawn(run);
 
 ...
 
 ?

It's just as wrong to catch Throwable there is at is anywhere. If you do that 
you'll catch Errors, and Errors are _supposed_ to kill your program. They 
indicate that something bad enough has occurred that it's better to terminate 
your program than continue.

So, yes, what you're doing will keep the thread from dying, but if you get an 
Error, you want to shut your program down, not try and keep it running. So, 
maybe catching Throwable would make sense if you had to then tell the other 
thread to terminate, but should rethrow the Throwable afterwards and let the 
thread die.

- Jonathan M Davis


Re: core/sys/windows/windows.d is executable

2013-09-28 Thread Joseph Rushton Wakeling

On 27/09/13 21:13, Jonathan M Davis wrote:

No, it should not be executable. The only time that it makes sense for a .d
file to be executable is when it's a script with something like #!/bin/rdmd at
the top, which certainly isn't the case for windows.d.


OK, I'll file a bug report and prepare a patch.  Might not arrive 'til next 
week.



Re: core/sys/windows/windows.d is executable

2013-09-28 Thread Joseph Rushton Wakeling

On 27/09/13 21:13, Jonathan M Davis wrote:

No, it should not be executable. The only time that it makes sense for a .d
file to be executable is when it's a script with something like #!/bin/rdmd at
the top, which certainly isn't the case for windows.d.


Is testing for correct permissions something that can be included in the 
auto-tester?  Seems likely that it could happen again by accident if someone 
edits windows.d on Windows (which is probably the most typical place to edit it).


Re: core/sys/windows/windows.d is executable

2013-09-28 Thread Benjamin Thaut

Am 28.09.2013 11:16, schrieb Joseph Rushton Wakeling:

On 27/09/13 21:13, Jonathan M Davis wrote:

No, it should not be executable. The only time that it makes sense for
a .d
file to be executable is when it's a script with something like
#!/bin/rdmd at
the top, which certainly isn't the case for windows.d.


Is testing for correct permissions something that can be included in the
auto-tester?  Seems likely that it could happen again by accident if
someone edits windows.d on Windows (which is probably the most typical
place to edit it).


Wouldn't it make more sense to automatically remove execute permission 
instead of testing against them? For someone only developing on windows 
it will not help when the autotester rejects the pull request just 
because it hase been made from a windows machine.


Re: core/sys/windows/windows.d is executable

2013-09-28 Thread Joseph Rushton Wakeling

On 28/09/13 11:19, Benjamin Thaut wrote:

Wouldn't it make more sense to automatically remove execute permission instead
of testing against them? For someone only developing on windows it will not help
when the autotester rejects the pull request just because it hase been made from
a windows machine.


Sure.  Can't remember off the top of my head if/how git handles this sort of 
thing.


Re: curl linux

2013-09-28 Thread Jordi Sayol
On 28/09/13 10:28, Alexandr Druzhinin wrote:
 I use curl in my application. If I link it with -lcurl - symbols are 
 undefined (libcurl3 installed), if I link with -lphobos2 - it links. So curl 
 is linked with libphobos2.so? But what to do if I need static linking? 
 (ubuntu 12.04 x86_64, dmd 2.063.2)
 

To link against libcurl (-lcurl) you need to install libcurl development files. 
On Ubuntu, install one of these three packages: libcurl4-openssl-dev, 
libcurl4-gnutls-dev or libcurl4-nss-dev.

For libcurl static linking you should link against all libraries that libcurl 
depends on.

-- 
Jordi Sayol


Re: core/sys/windows/windows.d is executable

2013-09-28 Thread Joseph Rushton Wakeling

On 28/09/13 11:12, Joseph Rushton Wakeling wrote:

OK, I'll file a bug report and prepare a patch.  Might not arrive 'til next 
week.


Pull request sent: https://github.com/D-Programming-Language/druntime/pull/618

I'll file a bug report next week, but to request that permissions are checked 
and corrected rather than for this single file's permissions status.




Re: Throwable catching

2013-09-28 Thread Alexandr Druzhinin

28.09.2013 15:50, Jonathan M Davis пишет:


It's just as wrong to catch Throwable there is at is anywhere. If you do that
you'll catch Errors, and Errors are _supposed_ to kill your program. They
indicate that something bad enough has occurred that it's better to terminate
your program than continue.

So, yes, what you're doing will keep the thread from dying, but if you get an
Error, you want to shut your program down, not try and keep it running. So,
maybe catching Throwable would make sense if you had to then tell the other
thread to terminate, but should rethrow the Throwable afterwards and let the
thread die.

- Jonathan M Davis

Just to clear - in my case child thread processes parent commands like a 
worker and every loop iteration isn't correlated with others before and 
after so I thought that just new iteration resets bad application state 
caused by Error - I was wrong?


Re: Throwable catching

2013-09-28 Thread Dicebot
On Saturday, 28 September 2013 at 12:26:37 UTC, Alexandr 
Druzhinin wrote:
Just to clear - in my case child thread processes parent 
commands like a worker and every loop iteration isn't 
correlated with others before and after so I thought that just 
new iteration resets bad application state caused by Error - I 
was wrong?


Error generally means unrecoverable application issue. It can 
result in undefined behavior if ignored, not matter what is the 
error locality. For example, out of memory error. Catching Errors 
may be viable as often as manual vtable patching or any similar 
low-level unsafe hack.


If your worker is _completely_ independent maybe you should just 
make it separate process that can be simply relaunched upon the 
Error.


Re: Throwable catching

2013-09-28 Thread monarch_dodra

On Saturday, 28 September 2013 at 12:26:37 UTC, Alexandr
Druzhinin wrote:
Just to clear - in my case child thread processes parent 
commands like a worker and every loop iteration isn't 
correlated with others before and after so I thought that just 
new iteration resets bad application state caused by Error - I 
was wrong?


It most certainly doesn't reset bad application state.

Chances are, if your loops are 100% non correlated, you *might*
get away with it, since you won't depend on the previous state.
However, you *will* have leaked destructors, maybe leaked some
memory, leaked file some handles, left some ressources locked, 
transactions open but neither failed nor passed etc...


Keeping the program (or in this case, thread) simply isn't a
good idea.

*Ideally* you should catch the error, send a high priority I
failed your command, and am about to die message to the parrent
thread, and then die. The parent thread should then deal with the
error (log that one of the jobs did not work, for example), and
then re-launch a fresh new thread.

But even then you'll have no
guarantees on the state of global shared variables. Also, I'm
unsure if when a thread dies, if its resources are relinquished
back to the OS, or if the entire program needs to die for that?
I think the entire program needs to die for that.

Long story short, an error means the program is *crashing*.
Keeping it going in such circumstances is just not a good idea.


Re: curl linux

2013-09-28 Thread Alexandr Druzhinin

28.09.2013 17:06, Jordi Sayol пишет:

On 28/09/13 10:28, Alexandr Druzhinin wrote:

I use curl in my application. If I link it with -lcurl - symbols are undefined 
(libcurl3 installed), if I link with -lphobos2 - it links. So curl is linked 
with libphobos2.so? But what to do if I need static linking? (ubuntu 12.04 
x86_64, dmd 2.063.2)



To link against libcurl (-lcurl) you need to install libcurl development files. On Ubuntu, install one of 
these three packages: libcurl4-openssl-dev, libcurl4-gnutls-dev or 
libcurl4-nss-dev.

For libcurl static linking you should link against all libraries that libcurl 
depends on.

Thank you for info. I have installed libcurl4-gnutls-dev - the same 
happens, symbols are undefined. But with -lphobos2 it links... Why 
linker don't find these symbols if libs are installed? Should I pass to 
linker some additional info in this case?


Re: Throwable catching

2013-09-28 Thread Alexandr Druzhinin

Thank you for info! I will redesign.


Re: curl linux

2013-09-28 Thread Jordi Sayol
On 28/09/13 14:41, Alexandr Druzhinin wrote:
 28.09.2013 17:06, Jordi Sayol пишет:
 On 28/09/13 10:28, Alexandr Druzhinin wrote:
 I use curl in my application. If I link it with -lcurl - symbols are 
 undefined (libcurl3 installed), if I link with -lphobos2 - it links. So 
 curl is linked with libphobos2.so? But what to do if I need static linking? 
 (ubuntu 12.04 x86_64, dmd 2.063.2)


 To link against libcurl (-lcurl) you need to install libcurl development 
 files. On Ubuntu, install one of these three packages: 
 libcurl4-openssl-dev, libcurl4-gnutls-dev or libcurl4-nss-dev.

 For libcurl static linking you should link against all libraries that 
 libcurl depends on.

 Thank you for info. I have installed libcurl4-gnutls-dev - the same 
 happens, symbols are undefined. But with -lphobos2 it links... Why linker 
 don't find these symbols if libs are installed? Should I pass to linker some 
 additional info in this case?
 

Can I see your full command line please?
$ dmd -lcurl 

-- 
Jordi Sayol



Re: dmd -D == ouch!!

2013-09-28 Thread Damien

Hi,

From The D Programming Language by Andrei Alexandrescu: If you 
forget about --main, don't worry; the linker will fluently and 
baroquely remind you of that in its native language, encrypted 
Klingon.


So I think that your issue is well known and not a development 
priority at the moment... :P


Cheers,
Damien


... but the error message is pretty opaque.  How feasible would 
it be to handle the case where the -D flag is passed with a 
nicer error message limiting itself to:


(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
To build only documentation, use dmd -o- -D


possible nested class/struct alias this bug

2013-09-28 Thread Eberhard

Hello,

I came across this unexpected error in the first example, so I 
tested similar scenarios, but couldn't make any sense of it.


Thanks, Eberhard.


class A {
   void foo() {}

   static class B {
  private A a;
  alias a this;

  void bar() {
 this.foo(); // works fine
 foo();  // Error: this for `foo` needs to be type 
`A` not type `A.B`

  }
   }
}

~

class A {
   void foo() {}
}

class B {
   void foo() {}

   static class C {
  private A a;
  alias a this;

  void bar() {
 this.foo(); // works fine
 foo();  // Error: this for `foo` needs to be type 
`B` not type `B.C`

  }
   }
}

~~

class A {
   void foo() {}
}

class B {
   // no foo

   static class C {
  private A a;
  alias a this;

  void bar() {
 this.foo(); // works fine
 foo();  // works fine
  }
   }
}


Re: curl linux

2013-09-28 Thread Alexandr Druzhinin

28.09.2013 20:14, Jordi Sayol пишет:


Can I see your full command line please?
$ dmd -lcurl 


I use dub, but I did rdmd version:
rdmd --build-only -I/home/drug/.dub/packages/derelict-master/import 
-I/home/drug/.dub/packages/glamour-master -version=Derelict3 
-version=gl3n -I/home/drug/.dub/packages/gl3n-master/ 
-I/home/drug/3rdparties/cairoD/src 
-I/home/drug/.dub/packages/arsd-master -version=CAIRO_HAS_PNG_FUNCTIONS 
-L-lphobos2 -L-L/home/drug/3rdparties/cairoD -L-lcairoD -L-lcairo -L-ldl 
-ofbin/geoviewer src/app.d


If I change -L-lphobos2 на -L-lcurl I get:
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function 
`_D3std3net4curl4Curl19_sharedStaticCtor34FZv':
std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticCtor34FZv+0xf): 
undefined reference to `curl_global_init'
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function 
`_D3std3net4curl4Curl19_sharedStaticDtor35FZv':
std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticDtor35FZv+0x5): 
undefined reference to `curl_global_cleanup'
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl_144c_140.o): In function 
`_D3std3net4curl4HTTP4Impl6__dtorMFZv':
std/net/curl.d:(.text._D3std3net4curl4HTTP4Impl6__dtorMFZv+0x19): 
undefined reference to `curl_slist_free_all'

...

and so on. That is in this case I have static linking but curl symbols 
are not definded somehow.


Re: Server is not active?

2013-09-28 Thread ollie
On Sat, 28 Sep 2013 08:42:16 +0200, wagtail wrote:

 I tried rewriting code with using ADDR_ANY, but do not work...

Ali Çehreli posted some examples in the D.learn group earlier.
He creates the socket then uses its member functions to setup
the connection, but it should work either way.

Try something like this:

auto inet = new InternetAddress(port);

The constructor for class InternetAddress will set addr to ADDR_ANY.
This should work if your server and client are on the same machine.
Otherwise you need to set the address to the IP of your server.

Would need some basic compilable code to know for sure how to make
that work in your situation.


Re: Server is not active?

2013-09-28 Thread Kapps
This is just a guess, but it is because you're setting the socket 
to be blocking after the call to accept? If it defaults to 
non-blocking, this would cause accept to return immediately, so 
the client connecting would fail as the server isn't currently 
accepting connections. Also to verify it's not a firewall issue, 
for connecting try using 127.0.0.1.


Re: Server is not active?

2013-09-28 Thread wagtail

On Saturday, 28 September 2013 at 17:13:06 UTC, ollie wrote:


Try something like this:

auto inet = new InternetAddress(port);


Oh,I'm sorry.
I forgot writing I already tried above instance.

The constructor for class InternetAddress will set addr to 
ADDR_ANY.
This should work if your server and client are on the same 
machine.

Otherwise you need to set the address to the IP of your server.


When my server and client are on the same machine,these succeed.
If I try communicating with other machine via global network,it 
do not work.

IP of my server which you say above should set to server side?


Re: Server is not active?

2013-09-28 Thread wagtail

On Saturday, 28 September 2013 at 23:25:20 UTC, Kapps wrote:
This is just a guess, but it is because you're setting the 
socket to be blocking after the call to accept? If it defaults 
to non-blocking, this would cause accept to return immediately, 
so the client connecting would fail as the server isn't 
currently accepting connections. Also to verify it's not a 
firewall issue, for connecting try using 127.0.0.1.


Thank you for your reply:)

Seeing your reply, I try commenting client.blocking(true) out,
but it do not work.

My server and client do work using 127.0.0.1,
So ,maybe I think firewall setting is correct.



Re: ieeeFlags are not getting set.

2013-09-28 Thread Damien

I have more information.
While doing some more experiment, I noticed that at some point a 
floating-point exception was thrown.


In the documentation, it says that floating-point exception are 
disabled by default. It further says that have floating-point 
exception enabled would disable the setting of ieeeFlags. I was 
also unable to disable those exception manually.


Still hoping someone telling me how stupid I am and that is not a 
D bug (omg this language has some puns potential...)

Damien