Re: D equivalent of C++ bind ?

2016-05-10 Thread André via Digitalmars-d-learn

On Tuesday, 10 May 2016 at 15:33:03 UTC, chmike wrote:

Thanks. This does the job but it's not as concise.


I've never missed C++'s bind functionality because D has first 
class support for delegates.


If async_task is changed to the following:

void async_task(void delegate(int error) cb) { . . . while cb(0) 
. . . }


You could just adapt a call to it using a lambda function:

async_task( (error) => myCb(error, count) );

D makes sure the enclosing stack is copied to the heap and count 
is reachable. Maybe this helps...


Regards,
André


Re: Multidimensional AA question

2015-11-28 Thread André via Digitalmars-d-learn
On Friday, 27 November 2015 at 04:21:41 UTC, Nicholas Wilson 
wrote:
AA are weird in that AFAIK you need to "initialise" them before 
you try to look suff up in them else they crash. i.e.

int[string] foo;
// auto e = "1" in foo; // crash AA not initialised
foo[ "blah"] = 0;
foo.remove("blah");
auto e = "1" in foo; //doesn't crash

have you tried using aa.get(key,default);?
i.e. contentAA.get(language,"english").get(section, 
"somedefault").get(section,0);


That doesn't work for my use case unfortunately. The object I am 
getting of this call isn't the one I would like update at 
[language][chapter][section]. I really need a pointer or 
reference to the object that is held my the map.



other than that are you likey to have missing sections? (i.e. 
do you need an AA for section or can you just use an array?)
similarly; does chapter need to be indexed by string? can you 
get away with indexing by chapter number and storing an array 
of chapter names and looking that up when needed?


Chapter is indeed the chapter's title. But you are right - the 
sections could be an usual array. Still the problem still is the 
same for the first two dimensions.


Re: Multidimensional AA question

2015-11-28 Thread André via Digitalmars-d-learn

On Friday, 27 November 2015 at 08:53:18 UTC, Jack Applegame wrote:

On Thursday, 26 November 2015 at 17:27:34 UTC, André wrote:
My question now is: is there some more elegant solution to 
achieve this? Something like in C++ when you have std::map's 
of std::map's and just access the elements and the entry is 
created implicitly?

No. But you can create a wrapper:
http://dpaste.dzfl.pl/80ad84e8f010


Thank you very much! That's a nice piece of code. I was looking 
for something like that in the standard library - to me it seems 
like something others might need regularly too.


Regards,
André


Multidimensional AA question

2015-11-26 Thread André via Digitalmars-d-learn

Hi,

I have a maybe trivial question on how to insert or update a 
given entry in a multidimensional AA. So I have this AA:


   /// language, chapter, section. Content is a magic struct
   Content[int][string][string] contentAA;

In some part of my code I want to either add a complete new entry 
or update an existing one. I just came up with this solution but 
it seems complex to me:


   string language, chapter;
   int section;
   Content* content;
   if (auto l = language in contentAA) {
   if (auto c = chapter in *l) {
  content = section in *c;
   }
   }
   if (!content) {
   contentAA[language][chapter][section] = Content();
   content = &contentAA[language][chapter][section];
   }
   /// work with content regardless whether it is updated or 
newly inserted


My question now is: is there some more elegant solution to 
achieve this? Something like in C++ when you have std::map's of 
std::map's and just access the elements and the entry is created 
implicitly? Basically I would want to just have this line working 
out of the box:


   content = &contentAA[language][chapter][section];

.. and the AA would make sure the element is created if it didn't 
exist before. I know I could create a function for that but I am 
looking for a standard approach that already exists.


Thanks!
André



Re: expand variadic template parameters

2015-03-10 Thread André

too many trees in front of my eyes.
Thanks for the answers.

Kind regards
André

On Tuesday, 10 March 2015 at 19:16:23 UTC, Adam D. Ruppe wrote:

On Tuesday, 10 March 2015 at 19:11:22 UTC, André wrote:

Is there a simple way to get it working?


The simplest: just write `bar(args);` - the variadic arguments 
will automatically expand.


expand variadic template parameters

2015-03-10 Thread André

Hi,

in this minified example I try to expand the variadic parmaters of
foo to bar:

import std.typecons;

void foo(T ...)(T args)
{
 bar(args.expand);
}

void bar(int i, string s){}

void main()
{
foo(1, "a");
}

I got the syntax error: no property 'expand' for type '(int,
string)'
I understand args is a TypeTuple and therefore expand is not
working.
Is there a simple way to get it working?

Kind regards
André


Re: InvalidMemoryOperationError@(0)

2014-11-17 Thread André

Thanks a lot.
I will forward this recommendation (DGUI BitBucket).

Kind regards
André

On Monday, 17 November 2014 at 16:40:18 UTC, ketmar via
Digitalmars-d-learn wrote:

On Mon, 17 Nov 2014 15:41:25 +
Andre via Digitalmars-d-learn 
 wrote:



~this()
{
foreach(cp; this._columns)
{   
}
}
don't do that in destructors. `_columns` field can be already 
collected

by GC.


Re: Learning asynchronous sockets in D (well actually C...)

2012-06-24 Thread Jarl André

On Sunday, 24 June 2012 at 23:04:14 UTC, Sean Kelly wrote:
On Jun 24, 2012, at 11:40 AM, "Jarl André" 
"@puremagic.com  
wrote:


Is it wrong to badge myself with asynchronous sockets? :)


Nope.  It's pretty weird stuff if you've never done event-based 
programming before.


I shouldn't glorify myself in any case. My first synchronous 
version was copy pasted from the socket listener example and then 
modified. When i figured that it was not accepted by folks that 
only want async stuff I found splat and updated it to d2. So the 
great feat must be that i managed to integrate splat and fix the 
segfaults following the d2 upgrade.


Re: Learning asynchronous sockets in D (well actually C...)

2012-06-24 Thread Jarl André

On Sunday, 24 June 2012 at 19:10:55 UTC, Tobias Pankrath wrote:
* add -g and -debug=splat (or any other keywords) to the build 
command



You don't need a keyword -debug is sufficient. To make the 
binary work with a debugger you does not even need -debug, only 
-g. -debug only includes code that's in a debug-block.



* gdb bin/SimpleServer
* continue (on breakpoints)
* run (to run the program)
* bt (for backtrace)

But of course, you all knew this before. But for a new D 
developer that has never done anything in C or C++ this was 
difficult as horses arse to understand.


Is it wrong to badge myself with asynchronous sockets? :)

https://github.com/jarlah/d2-simple-socket-server


I conclude from this, that you don't have any (much) experience 
with a unix c toolchain. May I ask what languages you come 
from? What are your biggest issues with learning D? I've got 
the feeling that many in the D community expect a C++ 
background from newcomers and we might need some material that 
lowers the barrier for people coming from say python.


And I'd advice you to get a good frontend for gdb :-) It really 
makes a difference.


You are absolutely right. I have no valuable experience with unix 
c toolchains. I have compiled c applications before, like hello 
world examples with gcc, and I have compiled packages in linux 
manually and know generally how c code compile. But I am 
practically foolish on old school programming in C and C++ (well 
C++ is actually totally different from C.. so I am less familiar 
with that compared to C).


I am coming from an expert Java EE background. Currently sitting 
everyday updating and adding new functionality in Java 6 
applications. I know that in Java 8 we get lambdas, hopefully it 
passes acceptance, yey! I have also done some hacking with 
Scala/Liftweb, Groovy/Grails and have touched on Ruby and other 
scripted languages. I was very interested before diving into D to 
learn a native language. D suited this requirement plus being 
almost Java like.


The thing that developers should come from a C/C++ background is 
totally not acceptable. So we need to add a "Introduction to D 
for Java developers" etc, that makes it easier to start hacking 
right away. It took me frickin two to three weeks to get familiar 
with the language, and now I am talking about the whole process. 
The language syntax in it self was so easy to understand that I 
got it straight away.


Re: Learning asynchronous sockets in D (well actually C...)

2012-06-24 Thread Jarl André
I have now completely and totally replaced the inner contents of 
my server library with modified Splat code. It ran so much faster 
that I was actually afraid I had got it wrong. It seemed not be 
any wrong with it, so adding Splat actually made it super kidding 
me fast. I have now learned a few valuable lessons:


* add -g and -debug=splat (or any other keywords) to the build 
command

* gdb bin/SimpleServer
* continue (on breakpoints)
* run (to run the program)
* bt (for backtrace)

But of course, you all knew this before. But for a new D 
developer that has never done anything in C or C++ this was 
difficult as horses arse to understand.


Is it wrong to badge myself with asynchronous sockets? :)

https://github.com/jarlah/d2-simple-socket-server


Learning asynchronous sockets in D (well actually C...)

2012-06-23 Thread Jarl André
The learning curve has been from like zero to "something". I am 
still grasping for some fundamental knowledge that I need to 
fully "get" whats going on. Had to read documentation for sockets 
in C to understand anything at all. That says a lot. Coming from 
BufferedReader hell in Java and did never "get" Java nio.


Looking at the Splat library, it was crude, and I didn't like the 
fact that it was D1. So I converted it to D2. Happy now, it 
works. My plan is to implement splat in the background inside of 
my simple socket server library. At this moment I have made a 
simple parrot server that currently replaces my old server in 
echoserver.d. So a bit of testing going on there atm.


I have learned the pattern "one person that runs back and forth 
with a bucket and fills it up and dumps it accordingly for each 
socket" is actually very effective. This is not very different 
from how i have implemented my simple socket server, except in my 
version i spawned threads that communicated and waited directly 
on the sockets. The parent thread only accepts sockets, I had 
Socket.select(sset,null,null); that in effect allows my spawned 
threads to do anything they wish for. Think I'll replace the 
inner contents of my old simple server with splat code.


Any pointers to what I should do next? Vibed is not an option. I 
do not like the approach. To much hassle for same result. I thnk 
the main reason for not using Vibed is that it is tightly 
connected to a toolchain. I like to have software that is 
independent.


https://github.com/jarlah/d2-simple-socket-server


Re: Does D have high-performance sockets

2012-06-13 Thread Jarl André

On Wednesday, 13 June 2012 at 10:24:58 UTC, Dmitry Olshansky
wrote:

On 13.06.2012 1:29, D Day wrote:

Are there any implementations of this anywhere for D?

I really only care about the windows platform - and have 
considered
writing this myself with IOCP and std.socket, but I figure 
someone else

must have already done something similar?


Take a look at vibe.d. While it looks like framework it could 
be used as library just as easy.

http://vibed.org/


My solution might be too simple. I made a simple socket server
that is single threaded, based on std.socket. Its really neat as
a need to have socket server library but I wouldn't recommend
using it in high performance applications. It imitates actually
QuickServer in Java, and the code shows clearly that I come from
a Java background

https://github.com/jarlah/d2-simple-socket-server


Segmentation fault hell in D

2012-06-08 Thread Jarl André
Evry single time I encounter them I yawn. It means using the next 
frickin hour to comment away code, add more log statements and 
try to eleminate whats creating the hell of bugz, segmantation 
fault. Why can't the compiler tell me anything else than the fact 
that i have referenced data that does not exist? Thanks I knew 
that. Now, please tell me where the error occured Jeezes.


Re: Simplified socket creation and handling

2012-06-05 Thread Jarl André

Thank you for the Windows compatibility. I will try it out ASAP.


I have now added some subtle changes to the server and example 
echo server. I have added an example for how byte streams can be 
passed to the server by converting them to base64. In my example 
the base64 encoded data is appended to a command. In this way I 
do not have to think about support for reading and writing bytes 
to and from sockets. Its a pain so I am trying to find a way to 
simplify this communication. I may incorporate this base64 
encode/decode into the server library, but at this point 
everything is in the echoserver.d file, visible for the naked eye 
:)


Question about Base64.decode(chomped)

Why is it possible to decode a string like "ddd"? I thought 
base64 was a strict format? I would like any encoder/decoder to 
throw exception on error not just returning whatever that was 
passed to the function.


Re: Simplified socket creation and handling

2012-06-02 Thread Jarl André
Now the similarity to the original quickserver library in java is 
so ripped off that I had an email sent over to the author asking 
for permission to continue on the api clone or alternatively 
change the api. Comments or suggestions? sucks totally or worth a 
penny?


Re: Socket identification key

2012-05-31 Thread Jarl André



I don't know why but for some reason this did not come to my
mind. LOL


Its a bit embarassing really because I work with Java every day 
and memory reference is a core feature. But I think the SocketSet 
buzzed my brain making me think that it gave me different objects 
or something. But anyway, lets forget this mumbo jumbo question.


I have updated my 
https://github.com/jarlah/d2-simple-socket-server with stateful 
overridable socket handlers, and to make it able to quickly setup 
the server I added a default one.


So, I think my brain is straight again now. Just got a bit messed 
up by the api.


Re: Socket identification key

2012-05-31 Thread Jarl André

On Thursday, 31 May 2012 at 14:46:42 UTC, Alex Rønne Petersen
wrote:
On 31-05-2012 16:44, "Jarl André" " 
wrote:

Hi

I have searched high and low to figure this one out. There 
does not
seems to be a an accessible way of getting a unique key for a 
socket. I
have learned that port numbers count a great deal but really 
shouldn't
there be some internal numbering or representation of each 
socket that
the developer can use in maps etc? Lets say I want to store 
statistics
for each individual client, but I don't want the client to 
"log in" or
something similiar. I want to automatically remember the 
handshake done

by the underlying TCP connection.

Is it possible to retrieve a unique key for a given socket? If 
this has
been discussed before it is very well hidden in the depths of 
asgar, so

please then enlighten me.

Cheers.


Your Socket object *is* the key. It's a reference, it has a 
memory address as value.


I don't know why but for some reason this did not come to my
mind. LOL


Socket identification key

2012-05-31 Thread Jarl André

Hi

I have searched high and low to figure this one out. There does 
not seems to be a an accessible way of getting a unique key for a 
socket. I have learned that port numbers count a great deal but 
really shouldn't there be some internal numbering or 
representation of each socket that the developer can use in maps 
etc? Lets say I want to store statistics for each individual 
client, but I don't want the client to "log in" or something 
similiar. I want to automatically remember the handshake done by 
the underlying TCP connection.


Is it possible to retrieve a unique key for a given socket? If 
this has been discussed before it is very well hidden in the 
depths of asgar, so please then enlighten me.


Cheers.


Re: Simplified socket creation and handling

2012-05-30 Thread Jarl André

On Wednesday, 30 May 2012 at 20:09:43 UTC, Jarl André wrote:

On Monday, 21 May 2012 at 19:06:24 UTC, Nathan M. Swan wrote:

On Monday, 21 May 2012 at 17:54:56 UTC, Adam D. Ruppe wrote:
On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan 
wrote:
It has some pitfalls (e.g. I can't find a good way to stop 
the server)


When I use it, I just leave it open in a terminal window.
Control+C can then kill it. (I'm on linux but I think the
same would apply on Windows.)

That's the only way right now. I was trying to make break;
work in that connect opApply thing, but it didn't work
right so there is no quit ability inside the app right now.


That's what I've done too, though it fails to call destructors.

I tried manager.quit(), but it results in segfaults for some 
reason (I think it has something to do with background 
threads).


Now I have removed the code that rendered the server 
incomatible with windows. Now documentation is the biggest todo 
on my list. Also notice I have added a bat script for running 
the simpleserver :)


I replied to the wrong author but anyway, if anyone wants to 
contribute to this project just tell me. Cheers.


Re: Simplified socket creation and handling

2012-05-30 Thread Jarl André

On Monday, 21 May 2012 at 19:06:24 UTC, Nathan M. Swan wrote:

On Monday, 21 May 2012 at 17:54:56 UTC, Adam D. Ruppe wrote:

On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan wrote:
It has some pitfalls (e.g. I can't find a good way to stop 
the server)


When I use it, I just leave it open in a terminal window.
Control+C can then kill it. (I'm on linux but I think the
same would apply on Windows.)

That's the only way right now. I was trying to make break;
work in that connect opApply thing, but it didn't work
right so there is no quit ability inside the app right now.


That's what I've done too, though it fails to call destructors.

I tried manager.quit(), but it results in segfaults for some 
reason (I think it has something to do with background threads).


Now I have removed the code that rendered the server incomatible 
with windows. Now documentation is the biggest todo on my list. 
Also notice I have added a bat script for running the 
simpleserver :)


Re: Simplified socket creation and handling

2012-05-30 Thread Jarl André

On Wednesday, 30 May 2012 at 08:40:48 UTC, Dejan Lekic wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a 
handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


I use QuickServer myself, and was thinking about creating 
something like that in D for quite some time...


Btw I updated my github project so now my little "quickserver" is
actually working :)


Re: Simplified socket creation and handling

2012-05-30 Thread Jarl André

On Wednesday, 30 May 2012 at 08:40:48 UTC, Dejan Lekic wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a 
handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


I use QuickServer myself, and was thinking about creating 
something like that in D for quite some time...


Good to hear! Your comment sparked the last in me to find out 
what was terribly wrong with my code. Spawning 1000 threads to 
the service never succeded. By investigating and copying from the 
listener example in std.socket library I found out that I had to 
use the SocketSet for all socket connections. In Java I could 
communicate based on a socket connection per client in multiple 
threads. With the berkeley api i am not able to do the same thing 
and it all fails tremendously if i try. Any reason why I cannot 
take a socket and communicate with its receive and send method 
solely?


Re: Converting from string to enum by name

2012-05-29 Thread Jarl André

On Monday, 28 May 2012 at 18:53:50 UTC, Ali Çehreli wrote:
On 05/28/2012 11:50 AM, "Jarl André" " 
wrote:


> 1. Is there a way to convert from string "INFO" to
LogLevel.INFO, by name?

conv.to can do that:

import std.conv;

enum LogLevel { ALL, INFO, WARNING }

void main()
{
enum l = to!LogLevel("INFO");
assert(l == LogLevel.INFO);
}

> 2. does it really not exist any functional logging libraries
for D2?

There has been discussions about that not too long ago.

Ali


Thanks. I have now implemented a logging library that actually 
looks to imitate log4j. If I log to any level then it checks if 
the current logLevel is equal to or lesser than the incoming 
loglevel. It might be using the wrong scale, e.g. ALL is 6 and 
OFF is 0, but it works. And its not really log4j so who cares ;)


Converting from string to enum by name

2012-05-28 Thread Jarl André

Hi

I have a project on github, 
https://github.com/jarlah/d2-simple-socket-server, where I have 
added very custom logger library. In this logger library I have 
an enum LogLevel that looks like enum LogLevel { ALL, INFO, 
WARNING etc }


Questions:

1. Is there a way to convert from string "INFO" to LogLevel.INFO, 
by name?
2. does it really not exist any functional logging libraries for 
D2?


I have made a very crude system where I specify the LogLevel that 
I want to be printed to stdout and have not yet begun to compare 
if loglevel is greater than or equal to whatever. thats my next 
assignment.


Re: Simplified socket creation and handling

2012-05-27 Thread Jarl André

Sorry for the typo: I do NOT understand it completely.


Thanks for the feedback! Well, for me I am a Java enterprise 
developer working with Java on Unix, but, I have worked with 
.NET in the past giving me a tiny portion of mercy to those 
that enjoys Visual Studio :) Its actually a blazing fast IDE. 
Enough digression.


The last days I have completely rewritten the library, and have 
also added a build script (you can just rename it from 
"simpleserver.sh" to "simpleserver.bat" and it will work. 
However, there are two things about this library that I am 
currently working on:


1. Windows support is lacking because I use a thread pool with 
imports for posix (unix systems) and I'm not extremely good at 
D yet.


2. For some reason I left an implementation of 
AbstractClientCommandHamdler in the quickserver library but it 
was intentional that this should reside in the simpleserver.d 
file, completely closing the library and making it possible to 
create a server without modifying the library at all.


3. I am wondering if I should export the threadpool into its 
own library so not to clutter up the quickserver.d file with 
Windows/Posix compability code. At the moment the server itslf 
is system independent.


So the answer is: yes I'll try to look at windows support, but 
if someone wants to help me I'll gladly say yes.


I completed todo 2 and 3. Now lets hope someone wants to 
contribute cross compability code on todo 1. It should be fairly 
easy since the threadpool now resides in its own module file.


Re: Simplified socket creation and handling

2012-05-27 Thread Jarl André

On Friday, 25 May 2012 at 20:55:12 UTC, Donald Duvall wrote:

On Friday, 25 May 2012 at 20:50:25 UTC, Donald Duvall wrote:

On Wednesday, 23 May 2012 at 19:24:53 UTC, Jarl André wrote:

On Wednesday, 23 May 2012 at 13:39:09 UTC, Jarl André wrote:
On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan 
wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol 
creation centered socket library. You don't have to write 
any channels and readers and what not. You just 
instantiate a server, configures the handlers (fill in 
classes that extends a handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always 
need control of the lower layers. Its not true. I care 
about protocol. Not sockets.


Is there any abstraction layers in phobos? Or is 
everything just as complex as before?


Check out arsd:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

I used cgi.d to make my own server easily (compile with 
-version=embedded_httpd). If you want more lower-level 
control, try a ListeningConnectionManager. To see how it's 
used, look at the code starting on line #1926.


It has some pitfalls (e.g. I can't find a good way to stop 
the server), but it is very nice in _easily_ starting up, 
with _zero_ config.


NMS


Thanks. It looks like a good option.

As it turns out I am very interested in having complete 
control of what type of service I am creating, so a library 
limiting me in some ways are not an option. On the other 
hand, I have investigated the listener example and have 
found out that I needed to generalize it a bit. Make a few 
interfaces, some implementations and my initial goal is to 
have end user code look excactly like QuickServers in Java. 
Why? Because sometimes you need simple command servers, lets 
say for polling an email or checking hardware status on a 
server and report it back, not worrying about blocking and 
async or whatever about sockets.


Another great advantage of making a "QuickServer" library is 
that its inner content can be replaced in the future without 
the end users knowing about. I have come far in the library 
making, but need some help understanding std.socket:


1.a. What is SocketSet and why do I need to pass it to 
Socket.select?
1.b. I only want to accept new sockets and I think its too 
much code for that


Even if questions is stupid please comment/correct me.


And here it comes:

https://github.com/jarlah/d2-simple-socket-server

This is my object oriented contribution to the problem.

Based on closed/open principe, in that expansion is done by 
adding new classes and not modifying the existing code.


Comments are appreciated.


Would it be possible for someone to write some documentation 
on this socket server and make it windows compatible?


I am just learning D and coming from C# sockets this is much 
different and I understand it completely. I would much 
appreciate any help with understanding sockets in D and any 
pointers in the right direction.


Sorry for the typo: I do NOT understand it completely.


Thanks for the feedback! Well, for me I am a Java enterprise 
developer working with Java on Unix, but, I have worked with .NET 
in the past giving me a tiny portion of mercy to those that 
enjoys Visual Studio :) Its actually a blazing fast IDE. Enough 
digression.


The last days I have completely rewritten the library, and have 
also added a build script (you can just rename it from 
"simpleserver.sh" to "simpleserver.bat" and it will work. 
However, there are two things about this library that I am 
currently working on:


1. Windows support is lacking because I use a thread pool with 
imports for posix (unix systems) and I'm not extremely good at D 
yet.


2. For some reason I left an implementation of 
AbstractClientCommandHamdler in the quickserver library but it 
was intentional that this should reside in the simpleserver.d 
file, completely closing the library and making it possible to 
create a server without modifying the library at all.


3. I am wondering if I should export the threadpool into its own 
library so not to clutter up the quickserver.d file with 
Windows/Posix compability code. At the moment the server itslf is 
system independent.


So the answer is: yes I'll try to look at windows support, but if 
someone wants to help me I'll gladly say yes.




Re: Simplified socket creation and handling

2012-05-23 Thread Jarl André

On Wednesday, 23 May 2012 at 13:39:09 UTC, Jarl André wrote:

On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a 
handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always 
need control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


Check out arsd:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

I used cgi.d to make my own server easily (compile with 
-version=embedded_httpd). If you want more lower-level 
control, try a ListeningConnectionManager. To see how it's 
used, look at the code starting on line #1926.


It has some pitfalls (e.g. I can't find a good way to stop the 
server), but it is very nice in _easily_ starting up, with 
_zero_ config.


NMS


Thanks. It looks like a good option.

As it turns out I am very interested in having complete control 
of what type of service I am creating, so a library limiting me 
in some ways are not an option. On the other hand, I have 
investigated the listener example and have found out that I 
needed to generalize it a bit. Make a few interfaces, some 
implementations and my initial goal is to have end user code 
look excactly like QuickServers in Java. Why? Because sometimes 
you need simple command servers, lets say for polling an email 
or checking hardware status on a server and report it back, not 
worrying about blocking and async or whatever about sockets.


Another great advantage of making a "QuickServer" library is 
that its inner content can be replaced in the future without 
the end users knowing about. I have come far in the library 
making, but need some help understanding std.socket:


1.a. What is SocketSet and why do I need to pass it to 
Socket.select?
1.b. I only want to accept new sockets and I think its too much 
code for that


Even if questions is stupid please comment/correct me.


And here it comes:

https://github.com/jarlah/d2-simple-socket-server

This is my object oriented contribution to the problem.

Based on closed/open principe, in that expansion is done by 
adding new classes and not modifying the existing code.


Comments are appreciated.


Re: Simplified socket creation and handling

2012-05-23 Thread Jarl André

On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a 
handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


Check out arsd:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

I used cgi.d to make my own server easily (compile with 
-version=embedded_httpd). If you want more lower-level control, 
try a ListeningConnectionManager. To see how it's used, look at 
the code starting on line #1926.


It has some pitfalls (e.g. I can't find a good way to stop the 
server), but it is very nice in _easily_ starting up, with 
_zero_ config.


NMS


Thanks. It looks like a good option.

As it turns out I am very interested in having complete control 
of what type of service I am creating, so a library limiting me 
in some ways are not an option. On the other hand, I have 
investigated the listener example and have found out that I 
needed to generalize it a bit. Make a few interfaces, some 
implementations and my initial goal is to have end user code look 
excactly like QuickServers in Java. Why? Because sometimes you 
need simple command servers, lets say for polling an email or 
checking hardware status on a server and report it back, not 
worrying about blocking and async or whatever about sockets.


Another great advantage of making a "QuickServer" library is that 
its inner content can be replaced in the future without the end 
users knowing about. I have come far in the library making, but 
need some help understanding std.socket:


1.a. What is SocketSet and why do I need to pass it to 
Socket.select?
1.b. I only want to accept new sockets and I think its too much 
code for that


Even if questions is stupid please comment/correct me.


Simplified socket creation and handling

2012-05-17 Thread Jarl André
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels and 
readers and what not. You just instantiate a server, configures 
the handlers (fill in classes that extends a handler interface) 
and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about protocol. 
Not sockets.


Is there any abstraction layers in phobos? Or is everything just 
as complex as before?


Re: parse json-string - operator overload error

2012-05-17 Thread Jarl André

On Wednesday, 1 December 2010 at 08:17:37 UTC, zusta wrote:

Hey guys,

I'm trying to read a JSON-formated file. The parsing of the 
file seems to be

correct, but I always get the following error:

"Error: no [] operator overload for type JSONValue".

For testing purposes, I also tried the code of
http://www.digitalmars.com/d/archives/digitalmars/D/std.json_API_improvement_
-_Request_for_code_review_117261.html#N117302 without success 
(same error).


My currently code looks like this:

import std.stdio : writeln;
import std.json;
import std.stream;
import std.conv;

void main(string[] args) {

File f = new File("test.json", FileMode.In);
string content = to!(string)(f.readString(f.available()));
JSONValue t = parseJSON(content);
writeln(t["test"]);
f.close();

}

I hope anyone can help to find out what's wrong with the code 
above.


Assuming the file reading was not the fault:

string content = "{ \"test\": \"1\"  }";
JSONValue[string] t = parseJSON(content).object;
writeln(t["test"].str);

This is one way to access the data in the file.


Re: std.json

2012-05-17 Thread Jarl André

On Thursday, 17 May 2012 at 18:36:22 UTC, Jarl André wrote:

On Thursday, 17 May 2012 at 14:08:27 UTC, Vincent wrote:

On Sunday, 25 March 2012 at 17:50:45 UTC, Andrea Fontana wrote:

Hope it's clear...


Nope, it's something like chess and have nothing common with 
simplicity of the real JSON usage! This is example from C#:


var p = JsonConvert.DeserializeObject("{some real 
JSON, not crapy EOS}");

var str = JsonConvert.SerializeObject(p);

That's it! And this is how it SHOULD be implemented. Cannot 
catch why this stupid realization came to standard library... 
:((


I'm pretty new to D, but I am an expert Java developer, self 
claimed. I am fluent in many other languages as well. In all 
languages there is a basis documentation.


Read the documentation for parseJSON and you'll see that it 
should be possible to send in a straight JSON string. I think 
the complex example is a bit stupid. It scares developers away 
from the lang.


Feel free to correct me of course.


The final proof of exisiting simplicity :)

JSONValue[string] value = parseJSON("{ \"test\": \"1\"
}").object;
writeln(value["test"].str);

This outputs "1"


Re: std.json

2012-05-17 Thread Jarl André

On Thursday, 17 May 2012 at 14:08:27 UTC, Vincent wrote:

On Sunday, 25 March 2012 at 17:50:45 UTC, Andrea Fontana wrote:

Hope it's clear...


Nope, it's something like chess and have nothing common with 
simplicity of the real JSON usage! This is example from C#:


var p = JsonConvert.DeserializeObject("{some real JSON, 
not crapy EOS}");

var str = JsonConvert.SerializeObject(p);

That's it! And this is how it SHOULD be implemented. Cannot 
catch why this stupid realization came to standard library... 
:((


I'm pretty new to D, but I am an expert Java developer, self 
claimed. I am fluent in many other languages as well. In all 
languages there is a basis documentation.


Read the documentation for parseJSON and you'll see that it 
should be possible to send in a straight JSON string. I think the 
complex example is a bit stupid. It scares developers away from 
the lang.


Feel free to correct me of course.


Range returned by iota and const

2012-04-17 Thread André Stein

Hi,

I'm trying to pass the range returned by iota to a function accepting 
the parameter as const. I got compilation errors when trying to use the 
index operator and after some investigation it turned out that opSlice 
of iota.Result isn't declared as const.


The function body of opSlice of iota.Result doesn't seem to mutate the 
range so is there any special reason why it isn't declared as such? (the 
same holds for opSlice).


Regards,
André


Re: Multiple definition of .../std/regex.d.912_ModuleInfoZ

2012-03-05 Thread André

Am 04.03.2012 16:27, schrieb Dmitry Olshansky:

On 04.03.2012 14:49, André wrote:

Hi,

I have a project compiled as libary and a seccond example project using
this library. The library is compiled without errors.


As it's a linker error I'd recommend checking that phobos and library
are built using the same compiler. Basically recompile and update phobos
library, then do clean rebuild of your lib.


The example project has 1 main module with an empty main function and
imports two modules of the library.

The errors following is given back from the compiler. If comment one
of the two import statements, then it is working.

I know there is no error in /std/regex.d. I do not even use this module.
But how to find out the root cause of this issue?

Kind regards
André




Hi Dmitry,
thanks for the help.
I found out, the compiler/linker parameter for the library project were
wrong and caused the error while linking the example project.

Kind regards
André




Multiple definition of .../std/regex.d.912_ModuleInfoZ

2012-03-04 Thread André

Hi,

I have a project compiled as libary and a seccond example project using 
this library. The library is compiled without errors.


The example project has 1 main module with an empty main function and 
imports two modules of the library.


The errors following is given back from the compiler. If comment one
of the two import statements, then it is working.

I know there is no error in /std/regex.d. I do not even use this module.
But how to find out the root cause of this issue?

Kind regards
André


dmd -c "main.d" -of"..proj_dir../F/FExample/FExample/obj/Debug/main.o" 
-I"/usr/include/d/dmd/phobos" -I"/usr/include/d/dmd/druntime/import" 
-I"/usr/include/d/dmd/gtkd" -I"..proj_dir../F/FEngine/FEngine"  -gc -debug


dmd -gc -debug -of"..proj_dir../F/FExample/FExample/bin/Debug/FExample" 
"obj/Debug/main.o"  "/usr/lib/libphobos2.a" 
-L"..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a" -L-lgtkd  -L-ldl


..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13a4.o):(.data+0x0): 
multiple definition of 
`_D39/usr/include/d/dmd/phobos/std/regex.d.912__ModuleInfoZ'
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13d8.o):(.data+0x0): 
first defined here
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13a4.o): In 
function `_D39/usr/include/d/dmd/phobos/std/regex.d.97__arrayZ':
(.text._D39/usr/include/d/dmd/phobos/std/regex.d.97__arrayZ+0x0): 
multiple definition of 
`_D39/usr/include/d/dmd/phobos/std/regex.d.97__arrayZ'
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13d8.o):(.text._D39/usr/include/d/dmd/phobos/std/regex.d.97__arrayZ+0x0): 
first defined here
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13a4.o): In 
function `_D39/usr/include/d/dmd/phobos/std/regex.d.98__ass--- errorlevel 1

ertFiZv':
(.text._D39/usr/include/d/dmd/phobos/std/regex.d.98__assertFiZv+0x0): 
multiple definition of 
`_D39/usr/include/d/dmd/phobos/std/regex.d.98__assertFiZv'
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13d8.o):(.text._D39/usr/include/d/dmd/phobos/std/regex.d.98__assertFiZv+0x0): 
first defined here
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13a4.o): In 
function `_D39/usr/include/d/dmd/phobos/std/regex.d.915__unittest_failFiZv':
(.text._D39/usr/include/d/dmd/phobos/std/regex.d.915__unittest_failFiZv+0x0): 
multiple definition of 
`_D39/usr/include/d/dmd/phobos/std/regex.d.915__unittest_failFiZv'
..proj_dir../F/FEngine/FEngine/bin/Debug/FEngine.a(regex_9_13d8.o):(.text._D39/usr/include/d/dmd/phobos/std/regex.d.915__unittest_failFiZv+0x0): 
first defined here

collect2: ld gab 1 als Ende-Status zurück
Exit code 1



Re: Trouble with -lib in linux "undefined reference to `_Dmain'"

2012-02-29 Thread André

you are right, that was the error.
Thanks.

Kind regards
André

Am 29.02.2012 18:27, schrieb Kevin Cox:

I think you need the -lib in the linker command (too?).

On Feb 29, 2012 12:25 PM, "André" mailto:an...@s-e-a-p.de>> wrote:

Hi,
I use Mono-D and have a hello world example which compiles fine.
I set the compiler option "-lib" and receives an error "undefined
reference to `_Dmain'".

Following commands are generated for the build process:
dmd -c "main.d"

-of"/home/user/Dokumente/__MonoDevelop/HelloWorld/__HelloWorld/obj/Debug/main.o"
-I"/usr/include/d/dmd/phobos"
-I"/usr/include/d/dmd/__druntime/import" -gc -debug -lib

dmd -gc -debug

-of"/home/user/Dokumente/__MonoDevelop/HelloWorld/__HelloWorld/bin/Debug/__HelloWorld"
"obj/Debug/main.o"

Do I miss an additional linux option or is the order of the commands
wrong?

Kind regards
André





Trouble with -lib in linux "undefined reference to `_Dmain'"

2012-02-29 Thread André

Hi,
I use Mono-D and have a hello world example which compiles fine.
I set the compiler option "-lib" and receives an error "undefined 
reference to `_Dmain'".


Following commands are generated for the build process:
dmd -c "main.d" 
-of"/home/user/Dokumente/MonoDevelop/HelloWorld/HelloWorld/obj/Debug/main.o" 
-I"/usr/include/d/dmd/phobos" -I"/usr/include/d/dmd/druntime/import" 
-gc -debug -lib


dmd -gc -debug 
-of"/home/user/Dokumente/MonoDevelop/HelloWorld/HelloWorld/bin/Debug/HelloWorld" 
"obj/Debug/main.o"


Do I miss an additional linux option or is the order of the commands wrong?

Kind regards
André


Function overload with template alias error

2011-12-24 Thread André Stein

Hi,

I'm trying to write a template function which takes a templated alias to 
another type:


struct test(T)
{
}

template aliasT(T)
{
alias test!(T) aliasT;
}

void foo(T)(test!T t) { // works
}

void foo2(T)(aliasT!T t) { // doesn't work
}

int main(string[] args)
{
test!(int) t;
aliasT!(int) t2;
foo(t);
foo2(t2); // error
return 0;
}


When foo2(t2) is called which takes an alias to test!T as argument I get 
the following error from dmd:


*(21): Error: template variant.foo2(T) does not match any function 
template declaration
*(21): Error: template variant.foo2(T) cannot deduce template function 
from argument types !()(test!(int))


I thought that aliasT!T and test!T have the same internal types and the 
compiler would be able deduce the template parameters. Am I missing 
something or is this a bug in DMD? This is a reduced test case from a 
piece of code where I tried to write an templated overload to 
std.variant.Algebraic.


Thanks,
André